summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-17 21:39:09 +0200
committerPierre Sassoulas <pierre.sassoulas@gmail.com>2021-06-17 23:09:55 +0200
commit2b2845c8a7b33f604c9807e05b08267483bb823c (patch)
tree40705b5e7e92e9ce36ebf897be59b9302dbde9ea /tests
parent8803b03416bf93ca02bd17dbb284f5fc0a7d657a (diff)
downloadastroid-git-2b2845c8a7b33f604c9807e05b08267483bb823c.tar.gz
Create a astroid.constants.py to avoid circular imports
And add PY3X type constants in it.
Diffstat (limited to 'tests')
-rw-r--r--tests/unittest_brain.py9
-rw-r--r--tests/unittest_builder.py4
-rw-r--r--tests/unittest_inference.py12
-rw-r--r--tests/unittest_nodes.py13
-rw-r--r--tests/unittest_protocols.py6
5 files changed, 18 insertions, 26 deletions
diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py
index 1380a97e..8343e397 100644
--- a/tests/unittest_brain.py
+++ b/tests/unittest_brain.py
@@ -44,6 +44,7 @@ import pytest
import astroid
from astroid import MANAGER, bases, builder, nodes, objects, test_utils, util
+from astroid.constants import PY37
from astroid.exceptions import AttributeInferenceError, InferenceError
try:
@@ -2730,7 +2731,7 @@ def test_http_client_brain():
assert isinstance(inferred, astroid.Instance)
-@pytest.mark.skipif(sys.version_info < (3, 7), reason="Needs 3.7+")
+@pytest.mark.skipif(not PY37, reason="Needs 3.7+")
def test_http_status_brain():
node = astroid.extract_node(
"""
@@ -2767,9 +2768,7 @@ def test_oserror_model():
assert strerror.value == ""
-@pytest.mark.skipif(
- sys.version_info < (3, 7), reason="Dynamic module attributes since Python 3.7"
-)
+@pytest.mark.skipif(not PY37, reason="Dynamic module attributes since Python 3.7")
def test_crypt_brain():
module = MANAGER.ast_from_module_name("crypt")
dynamic_attrs = [
@@ -2783,7 +2782,7 @@ def test_crypt_brain():
assert attr in module
-@pytest.mark.skipif(sys.version_info < (3, 7), reason="Dataclasses were added in 3.7")
+@pytest.mark.skipif(not PY37, reason="Dataclasses were added in 3.7")
def test_dataclasses():
code = """
import dataclasses
diff --git a/tests/unittest_builder.py b/tests/unittest_builder.py
index ca0ef861..8b9ccc5d 100644
--- a/tests/unittest_builder.py
+++ b/tests/unittest_builder.py
@@ -31,6 +31,7 @@ import unittest
import pytest
from astroid import Instance, builder, manager, nodes, test_utils, util
+from astroid.constants import PY38
from astroid.exceptions import (
AstroidBuildingError,
AstroidSyntaxError,
@@ -42,7 +43,6 @@ from . import resources
MANAGER = manager.AstroidManager()
BUILTINS = builtins.__name__
-PY38 = sys.version_info[:2] >= (3, 8)
class FromToLineNoTest(unittest.TestCase):
@@ -750,7 +750,7 @@ def test_module_build_dunder_file():
@pytest.mark.skipif(
- sys.version_info[:2] >= (3, 8),
+ PY38,
reason=(
"The builtin ast module does not fail with a specific error "
"for syntax error caused by invalid type comments."
diff --git a/tests/unittest_inference.py b/tests/unittest_inference.py
index 60344fda..0cd2dc3b 100644
--- a/tests/unittest_inference.py
+++ b/tests/unittest_inference.py
@@ -37,7 +37,6 @@
"""Tests for the astroid inference capabilities"""
import platform
-import sys
import textwrap
import unittest
from functools import partial
@@ -50,6 +49,7 @@ from astroid import decorators as decoratorsmod
from astroid import helpers, nodes, objects, test_utils, util
from astroid.bases import BUILTINS, BoundMethod, Instance, UnboundMethod
from astroid.builder import extract_node, parse
+from astroid.constants import PY38, PY39
from astroid.exceptions import (
AstroidTypeError,
AttributeInferenceError,
@@ -932,7 +932,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
self.assertEqual("module.D", should_be_D[0].qname())
@pytest.mark.skipif(
- sys.version_info >= (3, 8),
+ PY38,
reason="pathlib.Path cannot be inferred on Python 3.8",
)
def test_factory_methods_inside_binary_operation(self):
@@ -2495,7 +2495,7 @@ class InferenceTest(resources.SysPathSetup, unittest.TestCase):
]
# PEP-584 supports | for dictionary union
- if sys.version_info < (3, 9):
+ if not PY39:
ast_nodes.append(extract_node("{} | {} #@"))
expected.append(msg.format(op="|", lhs="dict", rhs="dict"))
@@ -5882,9 +5882,9 @@ def test_custom_decorators_for_classmethod_and_staticmethods(code, obj, obj_type
assert inferred.type == obj_type
-@pytest.mark.skipif(sys.version_info < (3, 8), reason="Needs dataclasses available")
+@pytest.mark.skipif(not PY38, reason="Needs dataclasses available")
@pytest.mark.skipif(
- sys.version_info >= (3, 9),
+ PY39,
reason="Exact inference with dataclasses (replace function) in python3.9",
)
def test_dataclasses_subscript_inference_recursion_error():
@@ -5908,7 +5908,7 @@ def test_dataclasses_subscript_inference_recursion_error():
@pytest.mark.skipif(
- sys.version_info < (3, 9),
+ not PY39,
reason="Exact inference with dataclasses (replace function) in python3.9",
)
def test_dataclasses_subscript_inference_recursion_error_39():
diff --git a/tests/unittest_nodes.py b/tests/unittest_nodes.py
index 5630b57e..3c67bbe4 100644
--- a/tests/unittest_nodes.py
+++ b/tests/unittest_nodes.py
@@ -40,6 +40,7 @@ import astroid
from astroid import bases, builder
from astroid import context as contextmod
from astroid import node_classes, nodes, parse, test_utils, transforms, util
+from astroid.constants import PY38, PY310
from astroid.exceptions import (
AstroidBuildingError,
AstroidSyntaxError,
@@ -50,7 +51,6 @@ from . import resources
abuilder = builder.AstroidBuilder()
BUILTINS = builtins.__name__
-PY38 = sys.version_info[:2] >= (3, 8)
try:
import typed_ast # pylint: disable=unused-import
@@ -265,7 +265,7 @@ class D(metaclass=abc.ABCMeta):
# This test is disabled on PyPy because we cannot get a release that has proper
# support for f-strings (we need 7.2 at least)
@pytest.mark.skipif(
- sys.version_info[:2] < (3, 6) or platform.python_implementation() == "PyPy",
+ platform.python_implementation() == "PyPy",
reason="Needs f-string support.",
)
def test_f_strings(self):
@@ -1237,7 +1237,6 @@ class AsyncGeneratorTest:
assert inferred.display_type() == "Generator"
-@pytest.mark.skipif(sys.version_info[:2] < (3, 6), reason="needs f-string support")
def test_f_string_correct_line_numbering():
"""Test that we generate correct line numbers for f-strings"""
node = astroid.extract_node(
@@ -1253,9 +1252,7 @@ def test_f_string_correct_line_numbering():
assert node.last_child().last_child().lineno == 5
-@pytest.mark.skipif(
- sys.version_info[:2] < (3, 8), reason="needs assignment expressions"
-)
+@pytest.mark.skipif(not PY38, reason="needs assignment expressions")
def test_assignment_expression():
code = """
if __(a := 1):
@@ -1371,9 +1368,7 @@ def test_is_generator_for_yield_in_aug_assign():
assert bool(node.is_generator())
-@pytest.mark.skipif(
- sys.version_info < (3, 10), reason="pattern matching was added in PY310"
-)
+@pytest.mark.skipif(not PY310, reason="pattern matching was added in PY310")
class TestPatternMatching:
@staticmethod
def test_match_simple():
diff --git a/tests/unittest_protocols.py b/tests/unittest_protocols.py
index 17c95963..bfdc0100 100644
--- a/tests/unittest_protocols.py
+++ b/tests/unittest_protocols.py
@@ -13,13 +13,13 @@
import contextlib
-import sys
import unittest
import pytest
import astroid
from astroid import extract_node, nodes, util
+from astroid.constants import PY38
from astroid.exceptions import InferenceError
from astroid.node_classes import AssignName, Const, Name, Starred
@@ -211,9 +211,7 @@ class ProtocolTests(unittest.TestCase):
parsed.accept(Visitor())
-@pytest.mark.skipif(
- sys.version_info[:2] < (3, 8), reason="needs assignment expressions"
-)
+@pytest.mark.skipif(not PY38, reason="needs assignment expressions")
def test_named_expr_inference():
code = """
if (a := 2) == 2: