Skip to content

Commit

Permalink
Merge pull request #22633 from ccordoba12/issue-22574
Browse files Browse the repository at this point in the history
PR: Fix debug file and cell buttons in Debugger toolbar
  • Loading branch information
ccordoba12 authored Oct 7, 2024
2 parents bebd026 + 9dfc87b commit 63f631f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
4 changes: 2 additions & 2 deletions external-deps/spyder-kernels/.gitrepo

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 35 additions & 3 deletions spyder/plugins/ipythonconsole/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Standard library imports
import os
import os.path as osp
from pathlib import Path
import sys
import threading
import traceback
Expand Down Expand Up @@ -203,26 +204,57 @@ def get_plugin(name):

debugger.get_plugin = get_plugin
debugger.on_ipython_console_available()

# Plugin setup
console.on_initialize()
console._register()
console.get_widget().matplotlib_status.register_ipythonconsole(console)

# Register handlers to run cells.
def get_file_code(fname, save_all=True):
"""
Get code from a file.
save_all is necessary to keep consistency with the handler registered
in the editor.
"""
path = Path(fname)
return path.read_text()

def get_cell(cell_id, fname):
"""
Get cell code from a file.
For now this only works with unnamed cells and cell separators of the
form `# %%`.
"""
path = Path(fname)
contents = path.read_text()
cells = contents.split("# %%")
return cells[int(cell_id)]

console.register_spyder_kernel_call_handler('get_file_code', get_file_code)
console.register_spyder_kernel_call_handler('run_cell', get_cell)

# Start client and show window
console.create_new_client(
special=special,
given_name=given_name,
path_to_custom_interpreter=path_to_custom_interpreter
)
window.setCentralWidget(console.get_widget())

# Set exclamation mark to True
configuration.set('debugger', 'pdb_use_exclamation_mark', True)

if os.name == 'nt':
qtbot.addWidget(window)

with qtbot.waitExposed(window):
window.resize(640, 480)
window.show()

# Set exclamation mark to True
configuration.set('debugger', 'pdb_use_exclamation_mark', True)

# Create new client for Matplotlb backend tests
if auto_backend or tk_backend:
qtbot.wait(SHELL_TIMEOUT)
console.create_new_client()
Expand Down
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 @@ -1656,6 +1656,45 @@ def test_recursive_pdb(ipyconsole, qtbot):
assert control.toPlainText().split()[-2:] == ["In", "[3]:"]


def test_pdb_magics_are_recursive(ipyconsole, qtbot, tmp_path):
"""
Check that calls to Pdb magics start a recursive debugger when called in
a debugging session.
"""
shell = ipyconsole.get_current_shellwidget()
control = ipyconsole.get_widget().get_focus_widget()

# Code to run
code = "a = 10\n\n# %%\n\nb = 20"

# Write code to file on disk
file = tmp_path / 'test_pdb_magics.py'
file.write_text(code)

# Filename in the format used when running magics from the main toolbar
fname = str(file).replace('\\', '/')

# Run file
with qtbot.waitSignal(shell.executed):
shell.execute(f"%debugfile {fname}")

# Run %debugfile in debugger
with qtbot.waitSignal(shell.executed):
shell.pdb_execute(f"%debugfile {fname}")

# Check that there are no errors and we started a recursive debugger
assert "error" not in control.toPlainText().lower()
assert "(IPdb [1]):" in control.toPlainText()

# Run %debugcell in debugger
with qtbot.waitSignal(shell.executed):
shell.pdb_execute(f"%debugcell -i 0 {fname}")

# Check that there are no errors and we started a recursive debugger
assert "error" not in control.toPlainText().lower()
assert "((IPdb [1])):" in control.toPlainText()


@flaky(max_runs=3)
@pytest.mark.skipif(os.name == 'nt', reason="Doesn't work on windows")
def test_stop_pdb(ipyconsole, qtbot):
Expand Down

0 comments on commit 63f631f

Please sign in to comment.