Skip to content

Commit bc82724

Browse files
committed
Include a test for the case when an inferenceError is raised
1 parent 02ae69b commit bc82724

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/unittest_brain.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,28 +1244,36 @@ def pear(self):
12441244
"module_with_class_named_enum",
12451245
)
12461246

1247-
attribute_node = astroid.extract_node(
1247+
attribute_nodes = astroid.extract_node(
12481248
"""
12491249
import module_with_class_named_enum
12501250
module_with_class_named_enum.Enum("apple", "orange") #@
1251+
typo_module_with_class_named_enum.Enum("apple", "orange") #@
12511252
"""
12521253
)
12531254

1254-
name_node = astroid.extract_node(
1255+
name_nodes = astroid.extract_node(
12551256
"""
12561257
from module_with_class_named_enum import Enum
12571258
Enum("apple", "orange") #@
1259+
TypoEnum("apple", "orange") #@
12581260
"""
12591261
)
12601262

1261-
inferred_attribute_node = attribute_node.inferred()[0]
1262-
inferred_name_node = name_node.inferred()[0]
1263-
for inferred in (inferred_attribute_node, inferred_name_node):
1263+
# Test that both of the successfully inferred `Name` & `Attribute`
1264+
# nodes refer to the user-defined Enum class.
1265+
for inferred in (attribute_nodes[0].inferred()[0], name_nodes[0].inferred()[0]):
12641266
assert isinstance(inferred, astroid.Instance)
12651267
assert inferred.name == "Enum"
12661268
assert inferred.qname() == "module_with_class_named_enum.Enum"
12671269
assert "pear" in inferred.locals
12681270

1271+
# Test that an `InferenceError` is raised when an attempt is made to
1272+
# infer a `Name` or `Attribute` node & they cannot be found.
1273+
for node in (attribute_nodes[1], name_nodes[1]):
1274+
with pytest.raises(InferenceError):
1275+
node.inferred()
1276+
12691277

12701278
@unittest.skipUnless(HAS_DATEUTIL, "This test requires the dateutil library.")
12711279
class DateutilBrainTest(unittest.TestCase):

0 commit comments

Comments
 (0)