From 1ff5fbdb773598d59d0a33729b4bbcb2e6d38f14 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Thu, 9 Feb 2023 22:48:16 +0100 Subject: [brain tests] Burst typing extensions from the main file --- tests/brain/test_brain.py | 32 --------------------------- tests/brain/test_typing_extensions.py | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 tests/brain/test_typing_extensions.py diff --git a/tests/brain/test_brain.py b/tests/brain/test_brain.py index 948dad26..a0bbd8ec 100644 --- a/tests/brain/test_brain.py +++ b/tests/brain/test_brain.py @@ -23,15 +23,6 @@ from astroid.exceptions import ( from astroid.nodes.node_classes import Const from astroid.nodes.scoped_nodes import ClassDef -try: - import typing_extensions # pylint: disable=unused-import - - HAS_TYPING_EXTENSIONS = True - HAS_TYPING_EXTENSIONS_TYPEVAR = hasattr(typing_extensions, "TypeVar") -except ImportError: - HAS_TYPING_EXTENSIONS = False - HAS_TYPING_EXTENSIONS_TYPEVAR = False - def assertEqualMro(klass: ClassDef, expected_mro: list[str]) -> None: """Check mro names.""" @@ -1519,29 +1510,6 @@ class TypingBrain(unittest.TestCase): assert i1.value == 2 # should be "Hello"! -@pytest.mark.skipif( - not HAS_TYPING_EXTENSIONS, - reason="These tests require the typing_extensions library", -) -class TestTypingExtensions: - @staticmethod - @pytest.mark.skipif( - not HAS_TYPING_EXTENSIONS_TYPEVAR, - reason="Need typing_extensions>=4.4.0 to test TypeVar", - ) - def test_typing_extensions_types() -> None: - ast_nodes = builder.extract_node( - """ - from typing_extensions import TypeVar - TypeVar('MyTypeVar', int, float, complex) #@ - TypeVar('AnyStr', str, bytes) #@ - """ - ) - for node in ast_nodes: - inferred = next(node.infer()) - assert isinstance(inferred, nodes.ClassDef) - - class ReBrainTest(unittest.TestCase): def test_regex_flags(self) -> None: names = [name for name in dir(re) if name.isupper()] diff --git a/tests/brain/test_typing_extensions.py b/tests/brain/test_typing_extensions.py new file mode 100644 index 00000000..27ee6ee5 --- /dev/null +++ b/tests/brain/test_typing_extensions.py @@ -0,0 +1,41 @@ +# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html +# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE +# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt + +from __future__ import annotations + +import pytest + +from astroid import builder, nodes + +try: + import typing_extensions # pylint: disable=unused-import + + HAS_TYPING_EXTENSIONS = True + HAS_TYPING_EXTENSIONS_TYPEVAR = hasattr(typing_extensions, "TypeVar") +except ImportError: + HAS_TYPING_EXTENSIONS = False + HAS_TYPING_EXTENSIONS_TYPEVAR = False + + +@pytest.mark.skipif( + not HAS_TYPING_EXTENSIONS, + reason="These tests require the typing_extensions library", +) +class TestTypingExtensions: + @staticmethod + @pytest.mark.skipif( + not HAS_TYPING_EXTENSIONS_TYPEVAR, + reason="Need typing_extensions>=4.4.0 to test TypeVar", + ) + def test_typing_extensions_types() -> None: + ast_nodes = builder.extract_node( + """ + from typing_extensions import TypeVar + TypeVar('MyTypeVar', int, float, complex) #@ + TypeVar('AnyStr', str, bytes) #@ + """ + ) + for node in ast_nodes: + inferred = next(node.infer()) + assert isinstance(inferred, nodes.ClassDef) -- cgit v1.2.1