Skip to content

Commit

Permalink
Merge from 3.1.x: PR #4175
Browse files Browse the repository at this point in the history
Fixes #3476
  • Loading branch information
ccordoba12 committed Feb 20, 2017
2 parents dabac0f + 8aa9d0a commit df17bbb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
37 changes: 37 additions & 0 deletions spyder/app/tests/test_mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions spyder/plugins/ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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':
Expand Down
8 changes: 7 additions & 1 deletion spyder/utils/ipython/spyder_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 6 additions & 0 deletions spyder/widgets/ipythonconsole/debugging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit df17bbb

Please sign in to comment.