summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhippo91 <guillaume.peillex@gmail.com>2021-01-18 19:13:22 +0100
committerhippo91 <guillaume.peillex@gmail.com>2021-01-18 19:13:22 +0100
commitbfad34705828d0b211c7908e204de4942f04d538 (patch)
tree1669b57cf0845a6838a17f8a214054c47bcbc054
parent6e9a69d568f35c8c44de42a9ba8fd34fb36c6e39 (diff)
downloadastroid-git-bfad34705828d0b211c7908e204de4942f04d538.tar.gz
Adds unittest for brain_type module
-rw-r--r--tests/unittest_brain.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unittest_brain.py b/tests/unittest_brain.py
index 7bb1f70f..0190ed3f 100644
--- a/tests/unittest_brain.py
+++ b/tests/unittest_brain.py
@@ -937,6 +937,33 @@ class IOBrainTest(unittest.TestCase):
self.assertEqual(raw.name, "FileIO")
+@test_utils.require_version("3.9")
+class TypeBrain(unittest.TestCase):
+ def test_type_subscript(self):
+ src = builder.extract_node(
+ """
+ a: type[int] = int
+ """
+ )
+ val_inf = src.annotation.value.inferred()[0]
+ self.assertIsInstance(val_inf, astroid.ClassDef)
+ self.assertEqual(val_inf.name, "type")
+ meth_inf = val_inf.getattr('__class_getitem__')[0]
+ self.assertIsInstance(meth_inf, astroid.FunctionDef)
+
+ def test_invalid_type_subscript(self):
+ src = builder.extract_node(
+ """
+ a: str[int] = "abc"
+ """
+ )
+ val_inf = src.annotation.value.inferred()[0]
+ self.assertIsInstance(val_inf, astroid.ClassDef)
+ self.assertEqual(val_inf.name, "str")
+ with self.assertRaises(astroid.exceptions.AttributeInferenceError):
+ meth_inf = val_inf.getattr('__class_getitem__')[0]
+
+
@test_utils.require_version("3.6")
class TypingBrain(unittest.TestCase):
def test_namedtuple_base(self):