From 85a05666314e4c60c0cea6fc1bf352e18739efb4 Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 19 Feb 2017 19:49:41 -0500 Subject: [PATCH 1/2] IPython console: Update breakpoints when new ones are added in the Editor --- spyder/plugins/ipythonconsole.py | 6 ++++++ spyder/utils/ipython/spyder_kernel.py | 8 +++++++- spyder/widgets/ipythonconsole/debugging.py | 6 ++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spyder/plugins/ipythonconsole.py b/spyder/plugins/ipythonconsole.py index d886c83aa24..a0eb984b092 100644 --- a/spyder/plugins/ipythonconsole.py +++ b/spyder/plugins/ipythonconsole.py @@ -794,6 +794,7 @@ def register_plugin(self): lambda fname, lineno, word, processevents: self.editor.load(fname, lineno, word, processevents=processevents)) + self.editor.breakpoints_saved.connect(self.set_spyder_breakpoints) self.editor.run_in_current_ipyclient.connect( self.run_script_in_current_client) self.main.workingdirectory.set_current_console_wd.connect( @@ -1215,6 +1216,11 @@ def pdb_has_stopped(self, fname, lineno, shellwidget): self.activateWindow() shellwidget._control.setFocus() + def set_spyder_breakpoints(self): + """Set Spyder breakpoints into all clients""" + for cl in self.clients: + cl.shellwidget.set_spyder_breakpoints() + #------ Public API (for kernels) ------------------------------------------ def ssh_tunnel(self, *args, **kwargs): if os.name == 'nt': diff --git a/spyder/utils/ipython/spyder_kernel.py b/spyder/utils/ipython/spyder_kernel.py index f4c4711b82d..b390d8569dc 100644 --- a/spyder/utils/ipython/spyder_kernel.py +++ b/spyder/utils/ipython/spyder_kernel.py @@ -83,7 +83,7 @@ def _pdb_locals(self): return {} # -- Public API --------------------------------------------------- - # For the Variable Explorer + # --- For the Variable Explorer def get_namespace_view(self): """ Return the namespace view @@ -329,6 +329,12 @@ def _register_pdb_session(self, pdb_obj): """Register Pdb session to use it later""" self._pdb_obj = pdb_obj + def _set_spyder_breakpoints(self): + """Set all Spyder breakpoints in an active pdb session""" + if not self._pdb_obj: + return + self._pdb_obj.set_spyder_breakpoints() + # --- For the Help plugin def _eval(self, text): """ diff --git a/spyder/widgets/ipythonconsole/debugging.py b/spyder/widgets/ipythonconsole/debugging.py index 93e44176019..8ba4e4c8718 100644 --- a/spyder/widgets/ipythonconsole/debugging.py +++ b/spyder/widgets/ipythonconsole/debugging.py @@ -72,6 +72,12 @@ def write_to_stdin(self, line): # Run post exec commands self._post_exec_input(line) + def set_spyder_breakpoints(self): + """Set Spyder breakpoints into a debugging session""" + if self._reading: + self.kernel_client.input( + "!get_ipython().kernel._set_spyder_breakpoints()") + # ---- Private API (defined by us) ------------------------------- def _post_exec_input(self, line): """Commands to be run after writing to stdin""" From 3e7b96de0e17f39e003b47f7dee65cd13dda299f Mon Sep 17 00:00:00 2001 From: Carlos Cordoba Date: Sun, 19 Feb 2017 20:42:51 -0500 Subject: [PATCH 2/2] Testing: Add a test for setting new breakpoints after a debugging session has started --- spyder/app/tests/test_mainwindow.py | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/spyder/app/tests/test_mainwindow.py b/spyder/app/tests/test_mainwindow.py index e4fd2a9f486..c69418e1431 100644 --- a/spyder/app/tests/test_mainwindow.py +++ b/spyder/app/tests/test_mainwindow.py @@ -78,6 +78,43 @@ def close_widget(): #============================================================================== # Tests #============================================================================== +@flaky(max_runs=10) +@pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows") +def test_set_new_breakpoints(main_window, qtbot): + """Test that new breakpoints are set in the IPython console.""" + # Wait until the window is fully up + shell = main_window.ipyconsole.get_current_shellwidget() + control = shell._control + qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT) + + # Clear all breakpoints + main_window.editor.clear_all_breakpoints() + + # Load test file + test_file = osp.join(LOCATION, 'script.py') + main_window.editor.load(test_file) + + # Click the debug button + debug_action = main_window.debug_toolbar_actions[0] + debug_button = main_window.debug_toolbar.widgetForAction(debug_action) + qtbot.mouseClick(debug_button, Qt.LeftButton) + qtbot.wait(1000) + + # Set a breakpoint + code_editor = main_window.editor.get_focus_widget() + code_editor.add_remove_breakpoint(line_number=6) + qtbot.wait(500) + + # Verify that the breakpoint was set + shell.kernel_client.input("b") + qtbot.wait(500) + assert "1 breakpoint keep yes at {}:6".format(test_file) in control.toPlainText() + + # Remove breakpoint and close test file + main_window.editor.clear_all_breakpoints() + main_window.editor.close_file() + + @flaky(max_runs=10) @pytest.mark.skipif(os.name == 'nt', reason="It times out sometimes on Windows") def test_run_code(main_window, qtbot):