Skip to content

Commit

Permalink
No longer raising BdbQuit
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaork committed Sep 25, 2020
1 parent 6ef9952 commit e4f86ac
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
1 change: 0 additions & 1 deletion madbg/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def trace_dispatch(self, frame, event, arg, check_debugging_global=False, done_c
return super().trace_dispatch(frame, event, arg)
except BdbQuit:
bdb_quit = True
raise
finally:
if (done_callback is not None) and (self.quitting or bdb_quit):
done_callback()
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install_requires =

[metadata]
name = madbg
version = 1.1.2
version = 1.1.3
description = A fully-featured remote debugger for python
author = Maor Kleinberger
author_email = kmaork@gmail.com
Expand Down
34 changes: 23 additions & 11 deletions tests/system/test_madbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
JOIN_TIMEOUT = 5


def run_set_trace_process(start_with_ctty, port) -> bool:
def run_set_trace(start_with_ctty, port):
enter_pty(start_with_ctty)
madbg.set_trace(port=port)


def run_set_trace_and_expect_var_to_change(start_with_ctty, port) -> bool:
"""
Set two vars to the same value, start the debugger, and return True if one of the vars has changed.
"""
Expand All @@ -23,7 +28,7 @@ def run_set_trace_process(start_with_ctty, port) -> bool:
return original_value != value_to_change


def run_set_trace_on_connect_process(start_with_ctty, port) -> bool:
def run_set_trace_on_connect(start_with_ctty, port) -> bool:
"""
Enter an infinite loop and break it using set_trace_on_connect.
"""
Expand All @@ -35,7 +40,7 @@ def run_set_trace_on_connect_process(start_with_ctty, port) -> bool:
return True


def run_client_process(port: int, debugger_input: bytes):
def run_client(port: int, debugger_input: bytes):
""" Run client process and return client's tty output """
master_fd = enter_pty(True)
os.write(master_fd, debugger_input)
Expand All @@ -54,29 +59,36 @@ def run_client_process(port: int, debugger_input: bytes):


def test_set_trace(port, start_debugger_with_ctty):
debugger_future = run_in_process(run_set_trace_process, start_debugger_with_ctty, port)
client_future = run_in_process(run_client_process, port, b'value_to_change += 1\nc\n')
debugger_future = run_in_process(run_set_trace_and_expect_var_to_change, start_debugger_with_ctty, port)
client_future = run_in_process(run_client, port, b'value_to_change += 1\nc\n')
assert debugger_future.result(JOIN_TIMEOUT)
client_output = client_future.result(JOIN_TIMEOUT)
# TODO: why does this assert fail?
#assert b'Closing connection' in client_output
# TODO: why does this assert fail? Problem in piping?
# assert b'Closing connection' in client_output


def test_set_trace_and_quit_debugger(port, start_debugger_with_ctty):
debugger_future = run_in_process(run_set_trace, start_debugger_with_ctty, port)
client_future = run_in_process(run_client, port, b'q\n')
debugger_future.result(JOIN_TIMEOUT)
client_future.result(JOIN_TIMEOUT)


def test_set_trace_with_failing_debugger(port, start_debugger_with_ctty, monkeypatch):
monkeypatch.setattr(RemoteIPythonDebugger, '__init__', Mock(side_effect=lambda *a, **k: 1 / 0))
debugger_future = run_in_process(run_set_trace_process, start_debugger_with_ctty, port)
client_future = run_in_process(run_client_process, port, b'value_to_change += 1\nc\n')
debugger_future = run_in_process(run_set_trace, start_debugger_with_ctty, port)
client_future = run_in_process(run_client, port, b'bla\n')
with raises(ZeroDivisionError):
debugger_future.result(JOIN_TIMEOUT)
client_output = client_future.result(JOIN_TIMEOUT)
assert ZeroDivisionError.__name__.encode() in client_output


def test_set_trace_on_connect(port, start_debugger_with_ctty):
debugger_future = run_in_process(run_set_trace_on_connect_process, start_debugger_with_ctty, port)
debugger_future = run_in_process(run_set_trace_on_connect, start_debugger_with_ctty, port)
# let the loop run a little
time.sleep(0.5)
assert not debugger_future.done()
client_future = run_in_process(run_client_process, port, b'conti = False\nc\n')
client_future = run_in_process(run_client, port, b'conti = False\nc\n')
assert debugger_future.result(JOIN_TIMEOUT)
client_future.result(JOIN_TIMEOUT)

0 comments on commit e4f86ac

Please sign in to comment.