Skip to content

Commit e6ba9b1

Browse files
add some test
1 parent 7bf07b8 commit e6ba9b1

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

Lib/runpy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def _get_module_details(mod_name, error=ImportError):
156156
if (d := _get_possible_name_list(mod_name)):
157157
from traceback import _calculate_closed_name
158158
if (suggestion := _calculate_closed_name(mod_name, d)):
159-
message += ". Did you mean: %r" % suggestion
159+
message += ". Did you mean: %r?" % suggestion
160160
raise error(message)
161161
if spec.submodule_search_locations is not None:
162162
if mod_name == "__main__" or mod_name.endswith(".__main__"):

Lib/test/test_cmd_line_script.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ def test_consistent_sys_path_for_module_execution(self):
771771
"-Im", "script_pkg", cwd=work_dir
772772
)
773773
traceback_lines = stderr.decode().splitlines()
774-
self.assertIn("No module named script_pkg", traceback_lines[-1])
774+
self.assertIn("No module named 'script_pkg'", traceback_lines[-1])
775775

776776
def test_nonexisting_script(self):
777777
# bpo-34783: "./python script.py" must not crash
@@ -829,6 +829,11 @@ def test_zipfile_run_filter_syntax_warnings_by_module(self):
829829
)
830830
self.assertEqual(err.count(b': SyntaxWarning: '), 12)
831831

832+
def test_typo_in_module_name_suggests_similar_module(self):
833+
# python -m randon -> expect suggestion for 'random'
834+
rc, out, err = assert_python_failure("-m", "randon")
835+
self.assertIn(b"No module named 'randon'", err)
836+
self.assertIn(b"Did you mean: 'random'?", err)
832837

833838
def tearDownModule():
834839
support.reap_children()

Lib/test/test_pdb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,7 +4210,7 @@ def test_module_without_a_main(self):
42104210
stdout, stderr = self._run_pdb(
42114211
['-m', module_name], "", expected_returncode=1
42124212
)
4213-
self.assertIn("ImportError: No module named t_main.__main__;", stdout)
4213+
self.assertIn("ImportError: No module named 't_main.__main__'", stdout)
42144214

42154215
def test_package_without_a_main(self):
42164216
pkg_name = 't_pkg'
@@ -4231,7 +4231,7 @@ def test_package_without_a_main(self):
42314231
def test_nonexistent_module(self):
42324232
assert not os.path.exists(os_helper.TESTFN)
42334233
stdout, stderr = self._run_pdb(["-m", os_helper.TESTFN], "", expected_returncode=1)
4234-
self.assertIn(f"ImportError: No module named {os_helper.TESTFN}", stdout)
4234+
self.assertIn(f"ImportError: No module named {os_helper.TESTFN!r}", stdout)
42354235

42364236
def test_dir_as_script(self):
42374237
with os_helper.temp_dir() as temp_dir:

0 commit comments

Comments
 (0)