Skip to content

Commit 4883d5c

Browse files
Fix ImportedModuleTests
1 parent 5aa0f51 commit 4883d5c

File tree

1 file changed

+54
-34
lines changed

1 file changed

+54
-34
lines changed

tests/unittest_inference.py

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6627,40 +6627,60 @@ def test_inference_of_items_on_module_dict() -> None:
66276627
builder.file_build(str(DATA_DIR / "module_dict_items_call" / "test.py"), "models")
66286628

66296629

6630-
class ImportedModuleTests(resources.AstroidCacheSetupMixin):
6631-
def test_imported_module_var_inferable(self) -> None:
6632-
"""
6633-
Module variables can be imported and inferred successfully as part of binary operators.
6634-
"""
6635-
mod1 = parse(("from top.mod import v as z\n" "w = [1] + z"), module_name="top")
6636-
parse("v = [2]", module_name="top.mod")
6637-
w_val = mod1.body[-1].value
6638-
i_w_val = next(w_val.infer())
6639-
assert i_w_val != util.Uninferable
6640-
assert i_w_val.as_string() == "[1, 2]"
6641-
6642-
def test_imported_module_var_inferable2(self) -> None:
6643-
"""Version list of strings."""
6644-
mod1 = parse(
6645-
("from top.mod import v as z\n" "w = ['1'] + z"), module_name="top"
6646-
)
6647-
parse("v = ['2']", module_name="top.mod")
6648-
w_val = mod1.body[-1].value
6649-
i_w_val = next(w_val.infer())
6650-
assert i_w_val != util.Uninferable
6651-
assert i_w_val.as_string() == "['1', '2']"
6652-
6653-
def test_imported_module_var_inferable3(self) -> None:
6654-
"""Version list of strings with a __dunder__ name."""
6655-
mod1 = parse(
6656-
("from top.mod import __dunder_var__ as v\n" "__dunder_var__ = ['w'] + v"),
6657-
module_name="top",
6658-
)
6659-
parse("__dunder_var__ = ['v']", module_name="top.mod")
6660-
w_val = mod1.body[-1].value
6661-
i_w_val = next(w_val.infer())
6662-
assert i_w_val != util.Uninferable
6663-
assert i_w_val.as_string() == "['w', 'v']"
6630+
def test_imported_module_var_inferable() -> None:
6631+
"""
6632+
Module variables can be imported and inferred successfully as part of binary operators.
6633+
"""
6634+
mod1 = parse(
6635+
textwrap.dedent(
6636+
"""
6637+
from top1.mod import v as z
6638+
w = [1] + z
6639+
"""
6640+
),
6641+
module_name="top1",
6642+
)
6643+
parse("v = [2]", module_name="top1.mod")
6644+
w_val = mod1.body[-1].value
6645+
i_w_val = next(w_val.infer())
6646+
assert i_w_val is not util.Uninferable
6647+
assert i_w_val.as_string() == "[1, 2]"
6648+
6649+
6650+
def test_imported_module_var_inferable2() -> None:
6651+
"""Version list of strings."""
6652+
mod2 = parse(
6653+
textwrap.dedent(
6654+
"""
6655+
from top2.mod import v as z
6656+
w = ['1'] + z
6657+
"""
6658+
),
6659+
module_name="top2",
6660+
)
6661+
parse("v = ['2']", module_name="top2.mod")
6662+
w_val = mod2.body[-1].value
6663+
i_w_val = next(w_val.infer())
6664+
assert i_w_val is not util.Uninferable
6665+
assert i_w_val.as_string() == "['1', '2']"
6666+
6667+
6668+
def test_imported_module_var_inferable3() -> None:
6669+
"""Version list of strings with a __dunder__ name."""
6670+
mod3 = parse(
6671+
textwrap.dedent(
6672+
"""
6673+
from top3.mod import __dunder_var__ as v
6674+
__dunder_var__ = ['w'] + v
6675+
"""
6676+
),
6677+
module_name="top",
6678+
)
6679+
parse("__dunder_var__ = ['v']", module_name="top3.mod")
6680+
w_val = mod3.body[-1].value
6681+
i_w_val = next(w_val.infer())
6682+
assert i_w_val is not util.Uninferable
6683+
assert i_w_val.as_string() == "['w', 'v']"
66646684

66656685

66666686
def test_recursion_on_inference_tip() -> None:

0 commit comments

Comments
 (0)