From efec623cb864f2d97f3e33353a22fdaa7adad5ba Mon Sep 17 00:00:00 2001 From: Shiva Shankar Dhamodharan Date: Wed, 14 Feb 2024 04:21:22 -0500 Subject: [PATCH] Merge pull request #270 from aktech/py-file-debug Add support for `py --debug` with file input --- lib/python/pyflyby/_dbg.py | 2 +- tests/test_cmdline.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 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 diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py index e7c549b2..4466519d 100644 --- a/tests/test_cmdline.py +++ b/tests/test_cmdline.py @@ -681,3 +681,24 @@ def test_tidy_imports_symlinks_bad_argument(): assert b"error: --symlinks must be one of" in proc_output assert output == input 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() +