Skip to content

Commit 699848b

Browse files
committed
Full coverage for _pyrepl._module_completer
1 parent 1bbfb9b commit 699848b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,8 @@ def test_relative_completions(self):
10411041
("_pyrepl", "from .readl\t\n", "from .readline"),
10421042
("_pyrepl", "from . import readl\t\n", "from . import readline"),
10431043
("_pyrepl", "from .readline import mul\t\n", "from .readline import multiline_input"),
1044+
("_pyrepl", "from .. import toodeep\t\n", "from .. import toodeep"),
1045+
("concurrent", "from .futures.i\t\n", "from .futures.interpreter"),
10441046
)
10451047
for package, code, expected in cases:
10461048
with self.subTest(code=code):
@@ -1079,6 +1081,18 @@ def test_no_fallback_on_regular_completion(self):
10791081
output = reader.readline()
10801082
self.assertEqual(output, expected)
10811083

1084+
def test_global_cache(self):
1085+
with (tempfile.TemporaryDirectory() as _dir1,
1086+
patch.object(sys, "path", [_dir1, *sys.path])):
1087+
dir1 = pathlib.Path(_dir1)
1088+
(dir1 / "mod_aa.py").mkdir()
1089+
(dir1 / "mod_bb.py").mkdir()
1090+
events = code_to_events("import mod_a\t\nimport mod_b\t\n")
1091+
reader = self.prepare_reader(events, namespace={})
1092+
output_1, output_2 = reader.readline(), reader.readline()
1093+
self.assertEqual(output_1, "import mod_aa")
1094+
self.assertEqual(output_2, "import mod_bb")
1095+
10821096
def test_hardcoded_stdlib_submodules(self):
10831097
cases = (
10841098
("import collections.\t\n", "import collections.abc"),
@@ -1299,6 +1313,7 @@ def test_parse_error(self):
12991313
'import ..foo',
13001314
'import .foo.bar',
13011315
'import foo; x = 1',
1316+
'import foo; 1,',
13021317
'import a.; x = 1',
13031318
'import a.b; x = 1',
13041319
'import a.b.; x = 1',
@@ -1318,6 +1333,8 @@ def test_parse_error(self):
13181333
'from foo import import',
13191334
'from foo import from',
13201335
'from foo import as',
1336+
'from \\x', # _tokenize SyntaxError -> tokenize TokenError
1337+
'if 1:\n pass\n\tpass', # _tokenize TabError -> tokenize TabError
13211338
)
13221339
for code in cases:
13231340
parser = ImportParser(code)

0 commit comments

Comments
 (0)