Skip to content

Commit

Permalink
Merge pull request #270 from aktech/py-file-debug
Browse files Browse the repository at this point in the history
Add support for `py --debug` with file input
  • Loading branch information
Shiva Shankar Dhamodharan committed Feb 14, 2024
1 parent 3e22f86 commit efec623
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions tests/test_cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit efec623

Please sign in to comment.