Skip to content

Commit

Permalink
Merge pull request #4247 from andfoy/nosigint_arg_fix
Browse files Browse the repository at this point in the history
PR: Added sigint argument to SpyderPdb constructor
  • Loading branch information
ccordoba12 authored Mar 11, 2017
2 parents 2194439 + 3f3016c commit 29dda43
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
38 changes: 37 additions & 1 deletion spyder/plugins/tests/test_ipythonconsole.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os.path as osp
import shutil
import tempfile
from textwrap import dedent

from flaky import flaky
import pytest
Expand Down Expand Up @@ -59,6 +60,42 @@ def close_widget():
#==============================================================================
# Tests
#==============================================================================
@flaky(max_runs=10)
@pytest.mark.skipif(os.name == 'nt', reason="It times out on Windows")
def test_run_doctest(ipyconsole, qtbot):
"""
Test that doctests can be run without problems
"""
shell = ipyconsole.get_current_shellwidget()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)

code = dedent('''
def add(x, y):
"""
>>> add(1, 2)
3
>>> add(5.1, 2.2)
7.3
"""
return x + y
''')

# Run code
with qtbot.waitSignal(shell.executed):
shell.execute(code)

# Import doctest
with qtbot.waitSignal(shell.executed):
shell.execute('import doctest')

# Run doctest
with qtbot.waitSignal(shell.executed):
shell.execute('doctest.testmod()')

# Assert that doctests were run correctly
assert "TestResults(failed=0, attempted=2)" in shell._control.toPlainText()


@flaky(max_runs=10)
@pytest.mark.skipif(os.name == 'nt', reason="It times out on Windows")
def test_mpl_backend_change(ipyconsole, qtbot):
Expand All @@ -67,7 +104,6 @@ def test_mpl_backend_change(ipyconsole, qtbot):
using the %matplotlib magic
"""
shell = ipyconsole.get_current_shellwidget()
client = ipyconsole.get_current_client()
qtbot.waitUntil(lambda: shell._prompt_html is not None, timeout=SHELL_TIMEOUT)

# Import Matplotlib
Expand Down
14 changes: 14 additions & 0 deletions spyder/utils/site/sitecustomize.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def in_qtconsole():
# Pdb adjustments
#==============================================================================
class SpyderPdb(pdb.Pdb):

send_initial_notification = True

def set_spyder_breakpoints(self):
Expand Down Expand Up @@ -556,8 +557,10 @@ def notify_spyder(self, frame):
monitor.notify_pdb_step(fname, lineno)
time.sleep(0.1)


pdb.Pdb = SpyderPdb


#XXX: I know, this function is now also implemented as is in utils/misc.py but
# I'm kind of reluctant to import spyder in sitecustomize, even if this
# import is very clean.
Expand Down Expand Up @@ -591,6 +594,13 @@ def decorator(func):
return func
return decorator


@monkeypatch_method(pdb.Pdb, 'Pdb')
def __init__(self, completekey='tab', stdin=None, stdout=None,
skip=None, nosigint=False):
self._old_Pdb___init__()


@monkeypatch_method(pdb.Pdb, 'Pdb')
def user_return(self, frame, return_value):
"""This function is called when a return trap is set here."""
Expand All @@ -603,6 +613,7 @@ def user_return(self, frame, return_value):
self._wait_for_mainpyfile = 0
self._old_Pdb_user_return(frame, return_value)


@monkeypatch_method(pdb.Pdb, 'Pdb')
def interaction(self, frame, traceback):
self.setup(frame, traceback)
Expand All @@ -612,6 +623,7 @@ def interaction(self, frame, traceback):
self.cmdloop()
self.forget()


@monkeypatch_method(pdb.Pdb, 'Pdb')
def reset(self):
self._old_Pdb_reset()
Expand All @@ -624,13 +636,15 @@ def reset(self):
monitor.register_pdb_session(self)
self.set_spyder_breakpoints()


#XXX: notify spyder on any pdb command (is that good or too lazy? i.e. is more
# specific behaviour desired?)
@monkeypatch_method(pdb.Pdb, 'Pdb')
def postcmd(self, stop, line):
self.notify_spyder(self.curframe)
return self._old_Pdb_postcmd(stop, line)


# Breakpoints don't work for files with non-ascii chars in Python 2
# Fixes Issue 1484
if PY2:
Expand Down

0 comments on commit 29dda43

Please sign in to comment.