Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,8 @@ def test_relative_import_completions(self):
(None, "from . import readl\t\n", "from . import readl"),
("_pyrepl", "from .readl\t\n", "from .readline"),
("_pyrepl", "from . import readl\t\n", "from . import readline"),
("_pyrepl", "from .. import toodeep\t\n", "from .. import toodeep"),
("concurrent", "from .futures.i\t\n", "from .futures.interpreter"),
)
for package, code, expected in cases:
with self.subTest(code=code):
Expand Down Expand Up @@ -1075,6 +1077,18 @@ def test_no_fallback_on_regular_completion(self):
output = reader.readline()
self.assertEqual(output, expected)

def test_global_cache(self):
with (tempfile.TemporaryDirectory() as _dir1,
patch.object(sys, "path", [_dir1, *sys.path])):
dir1 = pathlib.Path(_dir1)
(dir1 / "mod_aa.py").mkdir()
(dir1 / "mod_bb.py").mkdir()
events = code_to_events("import mod_a\t\nimport mod_b\t\n")
reader = self.prepare_reader(events, namespace={})
output_1, output_2 = reader.readline(), reader.readline()
self.assertEqual(output_1, "import mod_aa")
self.assertEqual(output_2, "import mod_bb")

def test_hardcoded_stdlib_submodules(self):
cases = (
("import collections.\t\n", "import collections.abc"),
Expand Down Expand Up @@ -1203,6 +1217,7 @@ def test_parse_error(self):
'import ..foo',
'import .foo.bar',
'import foo; x = 1',
'import foo; 1,',
'import a.; x = 1',
'import a.b; x = 1',
'import a.b.; x = 1',
Expand All @@ -1222,6 +1237,8 @@ def test_parse_error(self):
'from foo import import',
'from foo import from',
'from foo import as',
'from \\x', # _tokenize SyntaxError -> tokenize TokenError
'if 1:\n pass\n\tpass', # _tokenize TabError -> tokenize TabError
)
for code in cases:
parser = ImportParser(code)
Expand Down
Loading