Skip to content

Commit

Permalink
rewrite debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Peter committed Jul 4, 2020
1 parent 5597ecf commit b2c395f
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 296 deletions.
54 changes: 27 additions & 27 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ def test_move_to_first_breakpoint(main_window, qtbot, debugcell):
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')
# We need to press continue as we don't test yet if a breakpoint
# is in the cell
qtbot.keyClick(shell._control, 'c')
qtbot.keyClicks(shell._control, '!c')
qtbot.keyClick(shell._control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')
Expand All @@ -668,12 +668,12 @@ def test_move_to_first_breakpoint(main_window, qtbot, debugcell):
# Verify that we are at first breakpoint
shell.clear_console()
qtbot.wait(500)
shell.pdb_execute("list")
shell.pdb_execute("!list")
qtbot.wait(500)
assert "1--> 10 arr = np.array(li)" in control.toPlainText()

# Exit debugging
shell.pdb_execute("exit")
shell.pdb_execute("!exit")
qtbot.wait(500)

# Set breakpoint on first line with code
Expand Down Expand Up @@ -1115,7 +1115,7 @@ def test_set_new_breakpoints(main_window, qtbot):
qtbot.wait(500)

# Verify that the breakpoint was set
shell.pdb_execute("b")
shell.pdb_execute("!b")
qtbot.wait(500)
assert "1 breakpoint keep yes at {}:6".format(test_file) in control.toPlainText()

Expand Down Expand Up @@ -1251,7 +1251,7 @@ def test_run_code(main_window, qtbot, tmpdir):
modifier=Qt.AltModifier | Qt.ShiftModifier)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')
qtbot.keyClick(shell._control, 'c')
qtbot.keyClicks(shell._control, '!c')
qtbot.keyClick(shell._control, Qt.Key_Enter)

# Wait until the object has appeared in the variable explorer
Expand Down Expand Up @@ -1526,15 +1526,15 @@ def test_c_and_n_pdb_commands(main_window, qtbot):
qtbot.wait(500)

# Verify that c works
qtbot.keyClicks(control, 'c')
qtbot.keyClicks(control, '!c')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: nsb.editor.source_model.rowCount() == 1)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

# Verify that n works
qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: nsb.editor.source_model.rowCount() == 2)
Expand All @@ -1543,29 +1543,29 @@ def test_c_and_n_pdb_commands(main_window, qtbot):

# Verify that doesn't go to sitecustomize.py with next and stops
# the debugging session.
qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: nsb.editor.source_model.rowCount() == 3)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: 'In [2]:' in control.toPlainText())
Expand Down Expand Up @@ -1604,7 +1604,7 @@ def test_stop_dbg(main_window, qtbot):
qtbot.wait(1000)

# Move to the next line
shell.pdb_execute("n")
shell.pdb_execute("!n")
qtbot.wait(1000)

# Stop debugging
Expand Down Expand Up @@ -1657,7 +1657,7 @@ def test_change_cwd_dbg(main_window, qtbot):
qtbot.wait(500)

# Get cwd in console
qtbot.keyClicks(control, '!import os; os.getcwd()')
qtbot.keyClicks(control, 'import os; os.getcwd()')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.wait(1000)

Expand Down Expand Up @@ -1693,7 +1693,7 @@ def test_varexp_magic_dbg(main_window, qtbot):

# Get to an object that can be plotted
for _ in range(2):
qtbot.keyClicks(control, 'n')
qtbot.keyClicks(control, '!n')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')
Expand Down Expand Up @@ -2319,7 +2319,7 @@ def test_break_while_running(main_window, qtbot, tmpdir):
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

# Continue debugging
qtbot.keyClick(shell._control, 'c')
qtbot.keyClicks(shell._control, '!c')
qtbot.keyClick(shell._control, Qt.Key_Enter)
qtbot.wait(500)

Expand All @@ -2330,7 +2330,7 @@ def test_break_while_running(main_window, qtbot, tmpdir):
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

qtbot.keyClick(shell._control, 'q')
qtbot.keyClicks(shell._control, '!q')
qtbot.keyClick(shell._control, Qt.Key_Enter)
qtbot.wait(500)

Expand Down Expand Up @@ -2620,7 +2620,7 @@ def test_debug_unsaved_file(main_window, qtbot):

# There is a breakpoint, so it should continue
qtbot.waitUntil(
lambda: 'ipdb> continue' in shell._control.toPlainText())
lambda: 'ipdb> !continue' in shell._control.toPlainText())
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

Expand Down Expand Up @@ -2655,7 +2655,7 @@ def test_runcell(main_window, qtbot, tmpdir, debug):
qtbot.waitUntil(lambda: control.toPlainText().split()[-1] == 'ipdb>')

# Reach the 'name' input
shell.pdb_execute('c')
shell.pdb_execute('!c')

qtbot.wait(1000)

Expand Down Expand Up @@ -2883,11 +2883,11 @@ def test_runcell_pdb(main_window, qtbot):
# Start debugging
qtbot.mouseClick(debug_button, Qt.LeftButton)

for key in ['n', 'n', 's', 'n', 'n']:
for key in ['!n', '!n', '!s', '!n', '!n']:
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>',
timeout=3000)
qtbot.keyClick(shell._control, key)
qtbot.keyClicks(shell._control, key)
qtbot.keyClick(shell._control, Qt.Key_Enter)

qtbot.waitUntil(
Expand All @@ -2897,7 +2897,7 @@ def test_runcell_pdb(main_window, qtbot):
code_editor.setFocus()
# call runcell
qtbot.keyClick(code_editor, Qt.Key_Return, modifier=Qt.ShiftModifier)
qtbot.waitUntil(lambda: "!runcell" in shell._control.toPlainText())
qtbot.waitUntil(lambda: "runcell" in shell._control.toPlainText())
qtbot.waitUntil(
lambda: shell._control.toPlainText().split()[-1] == 'ipdb>')

Expand All @@ -2918,7 +2918,7 @@ def test_path_manager_updates_clients(qtbot, main_window, tmpdir):
dlg.add_path(folder)
qtbot.waitUntil(lambda: dlg.button_ok.isEnabled(), timeout=EVAL_TIMEOUT)

with qtbot.waitSignal(dlg.sig_path_changed):
with qtbot.waitSignal(dlg.sig_path_changed, timeout=EVAL_TIMEOUT):
dlg.button_ok.animateClick()

cmd = 'import sys;print(sys.path)'
Expand Down Expand Up @@ -2990,7 +2990,7 @@ def processEvents():
# Debug and open both files
shell.execute('%debug')
qtbot.waitUntil(lambda: control.toPlainText().split()[-1] == 'ipdb>')
qtbot.keyClick(control, 'u')
qtbot.keyClicks(control, '!u')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(lambda: control.toPlainText().split()[-1] == 'ipdb>')

Expand Down Expand Up @@ -3048,7 +3048,7 @@ def test_pbd_step(main_window, qtbot, tmpdir):
str(test_file)))

# Go up and enter second file
qtbot.keyClick(control, 'u')
qtbot.keyClicks(control, '!u')
qtbot.keyClick(control, Qt.Key_Enter)
qtbot.waitUntil(lambda: control.toPlainText().split()[-1] == 'ipdb>')
qtbot.waitUntil(
Expand Down Expand Up @@ -3204,9 +3204,9 @@ def test_running_namespace(main_window, qtbot, tmpdir):
timeout=3000)
assert 'b' not in nsb.editor.source_model._data
assert nsb.editor.source_model._data['a']['view'] == '5'

qtbot.waitUntil(shell.is_waiting_pdb_input)
with qtbot.waitSignal(shell.executed):
shell.execute('c')
shell.pdb_execute('!c')

# At the end, b should be back and a should be 10
qtbot.waitUntil(lambda: 'b' in nsb.editor.source_model._data)
Expand Down
3 changes: 2 additions & 1 deletion spyder/plugins/editor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,8 @@ def clear_breakpoint(self, filename, lineno):
def debug_command(self, command):
"""Debug actions"""
self.switch_to_plugin()
self.main.ipyconsole.pdb_execute(command, hidden=True, echo_code=False)
self.main.ipyconsole.pdb_execute(
"!" + command, hidden=True, echo_stack_entry=False)
focus_widget = self.main.ipyconsole.get_focus_widget()
if focus_widget:
focus_widget.setFocus()
Expand Down
13 changes: 4 additions & 9 deletions spyder/plugins/ipythonconsole/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def refresh_plugin(self):
self.main.variableexplorer.set_shellwidget_from_id(id(sw))
self.main.plots.set_shellwidget_from_id(id(sw))
self.main.help.set_shell(sw)
self.sig_pdb_state.emit(sw.in_debug_loop(), sw.get_pdb_last_step())
self.sig_pdb_state.emit(sw.is_debugging(), sw.get_pdb_last_step())
self.update_tabs_text()
self.sig_update_plugin_title.emit()

Expand Down Expand Up @@ -474,8 +474,6 @@ def run_script(self, filename, wdir, args, debug, post_mortem,
# still an execution taking place
# Fixes spyder-ide/spyder#7293.
pass
elif (client.shellwidget.in_debug_loop()):
client.shellwidget.pdb_execute('!' + line)
elif current_client:
self.execute_code(line, current_client, clear_variables)
else:
Expand Down Expand Up @@ -529,8 +527,6 @@ def norm(text):
# still an execution taking place
# Fixes spyder-ide/spyder#7293.
pass
elif (client.shellwidget.in_debug_loop()):
client.shellwidget.pdb_execute('!' + line)
else:
self.execute_code(line)
except AttributeError:
Expand Down Expand Up @@ -602,22 +598,21 @@ def execute_code(self, lines, current_client=True, clear_variables=False):
self.activateWindow()
self.get_current_client().get_control().setFocus()

def pdb_execute(self, line, hidden=False, echo_code=False):
def pdb_execute(self, line, hidden=False, echo_stack_entry=False):
sw = self.get_current_shellwidget()
if sw is not None:
# Needed to handle an error when kernel_client is None.
# See spyder-ide/spyder#7578.
try:
sw.set_pdb_echo_code(echo_code)
sw.pdb_execute(line, hidden)
sw.pdb_execute(line, hidden, echo_stack_entry)
except AttributeError:
pass

def get_pdb_state(self):
"""Get debugging state of the current console."""
sw = self.get_current_shellwidget()
if sw is not None:
return sw.in_debug_loop()
return sw.is_debugging()
return False

def get_pdb_last_step(self):
Expand Down

0 comments on commit b2c395f

Please sign in to comment.