From 6affffbea84c776510e59f64ba3fca31f9813472 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 17 Oct 2023 17:54:32 +0530 Subject: [PATCH 1/2] add support for py --debug filename --- lib/python/pyflyby/_dbg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/python/pyflyby/_dbg.py b/lib/python/pyflyby/_dbg.py index beb0dce8..0459de01 100644 --- a/lib/python/pyflyby/_dbg.py +++ b/lib/python/pyflyby/_dbg.py @@ -457,7 +457,7 @@ def debugger(*args, **kwargs): forked child. ''' from ._parse import PythonStatement, PythonBlock, FileText - if len(args) == 1: + if len(args) in {1, 2}: arg = args[0] elif len(args) == 0: arg = None From 4e2a3335946d1d2ffc5321d6d7e020b75498b535 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Tue, 17 Oct 2023 18:55:14 +0530 Subject: [PATCH 2/2] add test for debug with file input --- tests/test_cmdline.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index 23c0af88..8080f817 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -687,6 +687,27 @@ def test_tidy_imports_symlinks_bad_argument(): assert symlink_output == input +def test_debug_filetype_with_py(): + with tempfile.NamedTemporaryFile(suffix=".py", mode='w+') as f: + f.write(dedent(""" + sys.argv + """).lstrip()) + f.flush() + command = [BIN_DIR+"/py", "--debug", f.name] + + output_result = b"" + child = pexpect.spawn(' '.join(command), timeout=5) + child.expect('ipdb>') + output_result += child.before + child.sendline('c') + output_result += child.before + child.expect(pexpect.EOF) + output_result += child.before + + expected = "Entering debugger. Use 'n' to step, 'c' to run, 'q' to stop." + assert expected in output_result.decode() + + def test_tidy_imports_sorting(): with tempfile.NamedTemporaryFile(suffix=".py", mode='w+') as f: f.write(dedent("""