summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorRadislav Chugunov <52372310+chgnrdv@users.noreply.github.com>2023-10-16 09:38:07 (GMT)
committerGitHub <noreply@github.com>2023-10-16 09:38:07 (GMT)
commit162213f2db3835e1115178d38741544f4b4db416 (patch)
tree632af20372d4343db7943f5ace51c0df6a157ed3 /Lib/test
parentb75186f69edcf54615910a5cd707996144163ef7 (diff)
downloadcpython-162213f2db3835e1115178d38741544f4b4db416.zip
cpython-162213f2db3835e1115178d38741544f4b4db416.tar.gz
cpython-162213f2db3835e1115178d38741544f4b4db416.tar.bz2
gh-108791: Fix `pdb` CLI invalid argument handling (#108816)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_pdb.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index a668b6c..4701fa0 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -2820,8 +2820,7 @@ def bœr():
stdout, stderr = self._run_pdb(
['-m', module_name], "", expected_returncode=1
)
- self.assertIn("ImportError: No module named t_main.__main__",
- stdout.splitlines())
+ self.assertIn("ImportError: No module named t_main.__main__;", stdout)
def test_package_without_a_main(self):
pkg_name = 't_pkg'
@@ -2839,6 +2838,22 @@ def bœr():
"'t_pkg.t_main' is a package and cannot be directly executed",
stdout)
+ def test_nonexistent_module(self):
+ assert not os.path.exists(os_helper.TESTFN)
+ stdout, stderr = self._run_pdb(["-m", os_helper.TESTFN], "", expected_returncode=1)
+ self.assertIn(f"ImportError: No module named {os_helper.TESTFN}", stdout)
+
+ def test_dir_as_script(self):
+ with os_helper.temp_dir() as temp_dir:
+ stdout, stderr = self._run_pdb([temp_dir], "", expected_returncode=1)
+ self.assertIn(f"Error: {temp_dir} is a directory", stdout)
+
+ def test_invalid_cmd_line_options(self):
+ stdout, stderr = self._run_pdb(["-c"], "", expected_returncode=2)
+ self.assertIn(f"pdb: error: argument -c/--command: expected one argument", stdout.split('\n')[1])
+ stdout, stderr = self._run_pdb(["--spam", "-m", "pdb"], "", expected_returncode=2)
+ self.assertIn(f"pdb: error: unrecognized arguments: --spam", stdout.split('\n')[1])
+
def test_blocks_at_first_code_line(self):
script = """
#This is a comment, on line 2