Skip to content

Commit

Permalink
Merge from 5.x: PR #17089
Browse files Browse the repository at this point in the history
  • Loading branch information
ccordoba12 committed Feb 16, 2022
2 parents d9bf591 + a7d5f21 commit a9c003f
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4630,5 +4630,35 @@ def test_debug_unsaved_function(main_window, qtbot):
assert "1---> 2 print(1)" in control.toPlainText()


@pytest.mark.slow
def test_out_runfile_runcell(main_window, qtbot):
"""
Test that runcell and runfile return values if last statment
is expression.
"""
shell = main_window.ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)
control = main_window.ipyconsole.get_widget().get_focus_widget()
codes = {
"a = 1 + 1; a": (2, True),
"a = 1 + 3; a;": (4, False),
"a = 1 + 5\na": (6, True),
"a = 1 + 7\na;": (8, False)
}
for code in codes:
num, shown = codes[code]
# create new file
main_window.editor.new()
code_editor = main_window.editor.get_focus_widget()
code_editor.set_text(code)
with qtbot.waitSignal(shell.executed):
main_window.editor.run_cell()
if shown:
assert "]: " + str(num) in control.toPlainText()
else:
assert not "]: " + str(num) in control.toPlainText()


if __name__ == "__main__":
pytest.main()
39 changes: 39 additions & 0 deletions spyder/plugins/ipythonconsole/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,45 @@ def test_breakpoint_builtin(ipyconsole, qtbot, tmpdir):
assert 'IPdb [1]:' in control.toPlainText()


def test_pdb_out(ipyconsole, qtbot):
"""Test that browsing command history is working while debugging."""
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None,
timeout=SHELL_TIMEOUT)

# Give focus to the widget that's going to receive clicks
control = ipyconsole.get_widget().get_focus_widget()
control.setFocus()

# Enter debugging mode
with qtbot.waitSignal(shell.executed):
shell.execute('%debug print()')

# Generate some output
with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 12 + 1; a')

assert "[1]: 13" in control.toPlainText()

# Generate hide output
with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 14 + 1; a;')

assert "[2]: 15" not in control.toPlainText()

# Multiline
with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 16 + 1\na')

assert "[3]: 17" in control.toPlainText()

with qtbot.waitSignal(shell.executed):
shell.pdb_execute('a = 18 + 1\na;')

assert "[4]: 19" not in control.toPlainText()
assert "IPdb [4]:" in control.toPlainText()


@flaky(max_runs=3)
@pytest.mark.auto_backend
@pytest.mark.skipif(
Expand Down
23 changes: 23 additions & 0 deletions spyder/plugins/ipythonconsole/widgets/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,21 @@ def set_pdb_state(self, pdb_state):
if pdb_state is not None and isinstance(pdb_state, dict):
self.refresh_from_pdb(pdb_state)

def show_pdb_output(self, text):
"""Show Pdb output."""
self._append_plain_text(self.output_sep, before_prompt=True)
prompt = self._current_out_prompt()
self._append_html(
'<span class="out-prompt">%s</span>' % prompt,
before_prompt=True
)
# If the repr is multiline, make sure we start on a new line,
# so that its lines are aligned.
if "\n" in text and not self.output_sep.endswith("\n"):
self._append_plain_text('\n', before_prompt=True)
self._append_plain_text(text + self.output_sep2, before_prompt=True)
self._append_plain_text('\n', before_prompt=True)

def get_pdb_last_step(self):
"""Get last pdb step retrieved from a Pdb session."""
fname, lineno = self._pdb_frame_loc
Expand Down Expand Up @@ -471,6 +486,14 @@ def _current_prompt(self):
prompt = "({})".format(prompt)
return prompt + ": "

def _current_out_prompt(self):
"""Get current out prompt."""
prompt = "Out\u00A0\u00A0[{}]".format(self._pdb_history_input_number)
for i in range(self._pdb_in_loop - 1):
# Add recursive debugger prompt
prompt = "({})".format(prompt)
return prompt + ": "

def _handle_kernel_info_reply(self, rep):
"""Handle kernel info replies."""
super(DebuggingWidget, self)._handle_kernel_info_reply(rep)
Expand Down
1 change: 1 addition & 0 deletions spyder/plugins/ipythonconsole/widgets/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def __init__(self, ipyclient, additional_options, interpreter_versions,
handlers.update({
'pdb_state': self.set_pdb_state,
'pdb_execute': self.pdb_execute,
'show_pdb_output': self.show_pdb_output,
'get_pdb_settings': self.get_pdb_settings,
'set_debug_state': self.set_debug_state,
'update_syspath': self.update_syspath,
Expand Down

0 comments on commit a9c003f

Please sign in to comment.