Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move tests to a dedicated method
  • Loading branch information
loic-simon committed May 19, 2025
commit dd5940e15bac24243c3f7ea423f6c622ea409770
21 changes: 17 additions & 4 deletions Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def prepare_reader(self, events, namespace):
reader = ReadlineAlikeReader(console=console, config=config)
return reader

def test_import_completions(self):
def _only_stdlib_imports(self):
import importlib
# Make iter_modules() search only the standard library.
# This makes the test more reliable in case there are
Expand All @@ -938,22 +938,21 @@ def test_import_completions(self):
lib_path = os.path.dirname(importlib.__path__[0])
sys.path = [lib_path]

def test_import_completions(self):
self._only_stdlib_imports()
cases = (
("import path\t\n", "import pathlib"),
("import importlib.\t\tres\t\n", "import importlib.resources"),
("import importlib.resources.\t\ta\t\n", "import importlib.resources.abc"),
("import foo, impo\t\n", "import foo, importlib"),
("import foo as bar, impo\t\n", "import foo as bar, importlib"),
("import pri\t\n", "import pri"), # do not complete with "print("
("from impo\t\n", "from importlib"),
("from pri\t\n", "from pri"),
("from importlib.res\t\n", "from importlib.resources"),
("from importlib.\t\tres\t\n", "from importlib.resources"),
("from importlib.resources.ab\t\n", "from importlib.resources.abc"),
("from importlib import mac\t\n", "from importlib import machinery"),
("from importlib import res\t\n", "from importlib import resources"),
("from importlib.res\t import a\t\n", "from importlib.resources import abc"),
("from typing import Na\t\n", "from typing import Na"), # do not complete with "NameError("
)
for code, expected in cases:
with self.subTest(code=code):
Expand Down Expand Up @@ -991,6 +990,20 @@ def test_invalid_identifiers(self):
output = reader.readline()
self.assertEqual(output, expected)

def test_no_fallback_on_regular_completion(self):
self._only_stdlib_imports()
cases = (
("import pri\t\n", "import pri"),
("from pri\t\n", "from pri"),
("from typing import Na\t\n", "from typing import Na"),
)
for code, expected in cases:
with self.subTest(code=code):
events = code_to_events(code)
reader = self.prepare_reader(events, namespace={})
output = reader.readline()
self.assertEqual(output, expected)

def test_get_path_and_prefix(self):
cases = (
('', ('', '')),
Expand Down
Loading