Skip to content

Commit 8aa9d0a

Browse files
authored
Merge pull request #4175 from ccordoba12/ipyconsole-breakpoints
PR: Set new breakpoints in the IPython console while on a debugging session
2 parents ee6bca3 + 3e7b96d commit 8aa9d0a

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

Diff for: spyder/app/tests/test_mainwindow.py

+37
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,43 @@ def close_widget():
7878
#==============================================================================
7979
# Tests
8080
#==============================================================================
81+
@flaky(max_runs=10)
82+
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
83+
def test_set_new_breakpoints(main_window, qtbot):
84+
"""Test that new breakpoints are set in the IPython console."""
85+
# Wait until the window is fully up
86+
shell = main_window.ipyconsole.get_current_shellwidget()
87+
control = shell._control
88+
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)
89+
90+
# Clear all breakpoints
91+
main_window.editor.clear_all_breakpoints()
92+
93+
# Load test file
94+
test_file = osp.join(LOCATION, 'script.py')
95+
main_window.editor.load(test_file)
96+
97+
# Click the debug button
98+
debug_action = main_window.debug_toolbar_actions[0]
99+
debug_button = main_window.debug_toolbar.widgetForAction(debug_action)
100+
qtbot.mouseClick(debug_button, Qt.LeftButton)
101+
qtbot.wait(1000)
102+
103+
# Set a breakpoint
104+
code_editor = main_window.editor.get_focus_widget()
105+
code_editor.add_remove_breakpoint(line_number=6)
106+
qtbot.wait(500)
107+
108+
# Verify that the breakpoint was set
109+
shell.kernel_client.input("b")
110+
qtbot.wait(500)
111+
assert "1 breakpoint keep yes at {}:6".format(test_file) in control.toPlainText()
112+
113+
# Remove breakpoint and close test file
114+
main_window.editor.clear_all_breakpoints()
115+
main_window.editor.close_file()
116+
117+
81118
@flaky(max_runs=10)
82119
@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows")
83120
def test_run_code(main_window, qtbot):

Diff for: spyder/plugins/ipythonconsole.py

+6
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ def register_plugin(self):
794794
lambda fname, lineno, word, processevents:
795795
self.editor.load(fname, lineno, word,
796796
processevents=processevents))
797+
self.editor.breakpoints_saved.connect(self.set_spyder_breakpoints)
797798
self.editor.run_in_current_ipyclient.connect(
798799
self.run_script_in_current_client)
799800
self.main.workingdirectory.set_current_console_wd.connect(
@@ -1215,6 +1216,11 @@ def pdb_has_stopped(self, fname, lineno, shellwidget):
12151216
self.activateWindow()
12161217
shellwidget._control.setFocus()
12171218

1219+
def set_spyder_breakpoints(self):
1220+
"""Set Spyder breakpoints into all clients"""
1221+
for cl in self.clients:
1222+
cl.shellwidget.set_spyder_breakpoints()
1223+
12181224
#------ Public API (for kernels) ------------------------------------------
12191225
def ssh_tunnel(self, *args, **kwargs):
12201226
if os.name == 'nt':

Diff for: spyder/utils/ipython/spyder_kernel.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _pdb_locals(self):
8383
return {}
8484

8585
# -- Public API ---------------------------------------------------
86-
# For the Variable Explorer
86+
# --- For the Variable Explorer
8787
def get_namespace_view(self):
8888
"""
8989
Return the namespace view
@@ -329,6 +329,12 @@ def _register_pdb_session(self, pdb_obj):
329329
"""Register Pdb session to use it later"""
330330
self._pdb_obj = pdb_obj
331331

332+
def _set_spyder_breakpoints(self):
333+
"""Set all Spyder breakpoints in an active pdb session"""
334+
if not self._pdb_obj:
335+
return
336+
self._pdb_obj.set_spyder_breakpoints()
337+
332338
# --- For the Help plugin
333339
def _eval(self, text):
334340
"""

Diff for: spyder/widgets/ipythonconsole/debugging.py

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ def write_to_stdin(self, line):
7272
# Run post exec commands
7373
self._post_exec_input(line)
7474

75+
def set_spyder_breakpoints(self):
76+
"""Set Spyder breakpoints into a debugging session"""
77+
if self._reading:
78+
self.kernel_client.input(
79+
"!get_ipython().kernel._set_spyder_breakpoints()")
80+
7581
# ---- Private API (defined by us) -------------------------------
7682
def _post_exec_input(self, line):
7783
"""Commands to be run after writing to stdin"""

0 commit comments

Comments
 (0)