Skip to content

Commit

Permalink
Add failing test for ipythongh-4361
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Oct 9, 2013
1 parent f8bc560 commit bdcd3f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions IPython/core/tests/test_ultratb.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,12 @@ def test_changing_py_file(self):
# The SyntaxError should point to the correct line
with tt.AssertPrints(["7/", "SyntaxError"]):
ip.magic("run " + fname)

def test_non_syntaxerror(self):
# SyntaxTB may be called with an error other than a SyntaxError
# See e.g. gh-4361
try:
raise ValueError('QWERTY')
except ValueError:
with tt.AssertPrints('QWERTY'):
ip.showsyntaxerror()
6 changes: 6 additions & 0 deletions IPython/testing/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def __enter__(self):
setattr(sys, self.channel, self.buffer if self.suppress else self.tee)

def __exit__(self, etype, value, traceback):
if value is not None:
# If an error was raised, don't check anything else
return False
self.tee.flush()
setattr(sys, self.channel, self.orig_stream)
printed = self.buffer.getvalue()
Expand All @@ -375,6 +378,9 @@ class AssertNotPrints(AssertPrints):
Counterpart of AssertPrints"""
def __exit__(self, etype, value, traceback):
if value is not None:
# If an error was raised, don't check anything else
return False
self.tee.flush()
setattr(sys, self.channel, self.orig_stream)
printed = self.buffer.getvalue()
Expand Down

0 comments on commit bdcd3f6

Please sign in to comment.