]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-140870: Full coverage for _pyrepl._module_completer (GH-143244) (#143260)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 28 Dec 2025 19:31:02 +0000 (20:31 +0100)
committerGitHub <noreply@github.com>
Sun, 28 Dec 2025 19:31:02 +0000 (19:31 +0000)
gh-140870: Full coverage for _pyrepl._module_completer (GH-143244)

Full coverage for _pyrepl._module_completer
(cherry picked from commit c3febba73b05bb15b15930d545b479a3245cfe11)

Co-authored-by: Loïc Simon <loic.simon@napta.io>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Lib/test/test_pyrepl/test_pyrepl.py

index c1485af524aebcaa68c68804519de7bd805c2458..9cb60951586fc37583b7f2569d9609d5f7da61a5 100644 (file)
@@ -1037,6 +1037,8 @@ class TestPyReplModuleCompleter(TestCase):
             (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):
@@ -1075,6 +1077,18 @@ class TestPyReplModuleCompleter(TestCase):
                 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"),
@@ -1203,6 +1217,7 @@ class TestPyReplModuleCompleter(TestCase):
             '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',
@@ -1222,6 +1237,8 @@ class TestPyReplModuleCompleter(TestCase):
             '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)