@@ -4765,7 +4765,26 @@ def foo(self):
47654765 """
47664766 stdout , stderr = self .run_pdb_script (script , commands )
47674767 self .assertIn ("The specified object 'C.foo' is not a function" , stdout )
4768-
4768+ def test_end_of_options_separator (self ):
4769+ # gh-148615: Test parsing when '--' separator is used
4770+ script = "import sys; print(f'ARGS: {sys.argv[1:]}')"
4771+ with open (os_helper .TESTFN , 'w' , encoding = 'utf-8' ) as f :
4772+ f .write (script )
4773+ stdout , _ = self ._run_pdb (['--' , os_helper .TESTFN , '-foo' ], 'c\n q' )
4774+ self .assertIn ("ARGS: ['-foo']" , stdout )
4775+ stdout , _ = self ._run_pdb (['-c' , 'continue' , '--' , os_helper .TESTFN , '-c' , 'foo' ], 'q' )
4776+ self .assertIn ("ARGS: ['-c', 'foo']" , stdout )
4777+ stdout , stderr = self ._run_pdb (['--' ], 'q' , expected_returncode = 2 )
4778+ self .assertIn ("missing script or module to run" , stderr )
4779+ stdout , stderr = self ._run_pdb (['-x' , '--' , os_helper .TESTFN ], 'q' , expected_returncode = 2 )
4780+ self .assertIn ("unrecognized arguments: -x" , stderr )
4781+ stdout , _ = self ._run_pdb ([os_helper .TESTFN , '--' , 'arg' ], 'c\n q' )
4782+ self .assertIn ("ARGS: ['--', 'arg']" , stdout )
4783+ with os_helper .temp_cwd ():
4784+ with open ('mymod.py' , 'w' , encoding = 'utf-8' ) as f :
4785+ f .write (script )
4786+ stdout , _ = self ._run_pdb (['-m' , 'mymod' , '--' , 'arg' ], 'c\n q' )
4787+ self .assertIn ("ARGS: ['--', 'arg']" , stdout )
47694788
47704789class ChecklineTests (unittest .TestCase ):
47714790 def setUp (self ):
@@ -5210,34 +5229,6 @@ def test_interact_completion(self):
52105229 self .assertIn (b'84' , output )
52115230
52125231
5213- class PdbCommandLineTestCase (unittest .TestCase ):
5214- def test_end_of_options_separator (self ):
5215- # gh-148615: Test parsing when '--' separator is used
5216- from pdb import parse_args
5217- with patch ('sys.argv' , ['pdb.py' , '--' , 'my_script.py' , '-foo' ]):
5218- opts , args = parse_args ()
5219- self .assertEqual (args , ['my_script.py' , '-foo' ])
5220- with patch ('sys.argv' , ['pdb.py' , '-c' , 'continue' , '--' , 'my_script.py' , '-c' , 'foo' ]):
5221- opts , args = parse_args ()
5222- self .assertEqual (opts .commands , ['continue' ])
5223- self .assertEqual (args , ['my_script.py' , '-c' , 'foo' ])
5224- with patch ('sys.argv' , ['pdb.py' , '--' ]):
5225- with support .captured_stderr () as stderr :
5226- with self .assertRaises (SystemExit ):
5227- parse_args ()
5228- self .assertIn ("missing script or module to run" , stderr .getvalue ())
5229- with patch ('sys.argv' , ['pdb.py' , '-x' , '--' , 'my_script.py' ]):
5230- with support .captured_stderr () as stderr :
5231- with self .assertRaises (SystemExit ):
5232- parse_args ()
5233- self .assertIn ("unrecognized arguments: -x" , stderr .getvalue ())
5234- with patch ('sys.argv' , ['pdb.py' , 'foo' , '--' , 'my_script.py' ]):
5235- opts , args = parse_args ()
5236- self .assertEqual (args , ['foo' , '--' , 'my_script.py' ])
5237- with patch ('sys.argv' , ['pdb.py' , '-m' , 'my_module' , '--' , 'foo' ]):
5238- opts , args = parse_args ()
5239- self .assertEqual (opts .module , 'my_module' )
5240- self .assertEqual (args , ['--' , 'foo' ])
52415232
52425233def load_tests (loader , tests , pattern ):
52435234 from test import test_pdb
0 commit comments