Show More
@@ -138,3 +138,12 b' class SyntaxErrorTest(unittest.TestCase):' | |||||
138 | # The SyntaxError should point to the correct line |
|
138 | # The SyntaxError should point to the correct line | |
139 | with tt.AssertPrints(["7/", "SyntaxError"]): |
|
139 | with tt.AssertPrints(["7/", "SyntaxError"]): | |
140 | ip.magic("run " + fname) |
|
140 | ip.magic("run " + fname) | |
|
141 | ||||
|
142 | def test_non_syntaxerror(self): | |||
|
143 | # SyntaxTB may be called with an error other than a SyntaxError | |||
|
144 | # See e.g. gh-4361 | |||
|
145 | try: | |||
|
146 | raise ValueError('QWERTY') | |||
|
147 | except ValueError: | |||
|
148 | with tt.AssertPrints('QWERTY'): | |||
|
149 | ip.showsyntaxerror() |
@@ -1202,7 +1202,8 b' class SyntaxTB(ListTB):' | |||||
1202 | # If the source file has been edited, the line in the syntax error can |
|
1202 | # If the source file has been edited, the line in the syntax error can | |
1203 | # be wrong (retrieved from an outdated cache). This replaces it with |
|
1203 | # be wrong (retrieved from an outdated cache). This replaces it with | |
1204 | # the current value. |
|
1204 | # the current value. | |
1205 |
if isinstance(value |
|
1205 | if isinstance(value, SyntaxError) \ | |
|
1206 | and isinstance(value.filename, py3compat.string_types) \ | |||
1206 | and isinstance(value.lineno, int): |
|
1207 | and isinstance(value.lineno, int): | |
1207 | linecache.checkcache(value.filename) |
|
1208 | linecache.checkcache(value.filename) | |
1208 | newtext = ulinecache.getline(value.filename, value.lineno) |
|
1209 | newtext = ulinecache.getline(value.filename, value.lineno) |
@@ -357,6 +357,9 b' class AssertPrints(object):' | |||||
357 | setattr(sys, self.channel, self.buffer if self.suppress else self.tee) |
|
357 | setattr(sys, self.channel, self.buffer if self.suppress else self.tee) | |
358 |
|
358 | |||
359 | def __exit__(self, etype, value, traceback): |
|
359 | def __exit__(self, etype, value, traceback): | |
|
360 | if value is not None: | |||
|
361 | # If an error was raised, don't check anything else | |||
|
362 | return False | |||
360 | self.tee.flush() |
|
363 | self.tee.flush() | |
361 | setattr(sys, self.channel, self.orig_stream) |
|
364 | setattr(sys, self.channel, self.orig_stream) | |
362 | printed = self.buffer.getvalue() |
|
365 | printed = self.buffer.getvalue() | |
@@ -375,6 +378,9 b' class AssertNotPrints(AssertPrints):' | |||||
375 |
|
378 | |||
376 | Counterpart of AssertPrints""" |
|
379 | Counterpart of AssertPrints""" | |
377 | def __exit__(self, etype, value, traceback): |
|
380 | def __exit__(self, etype, value, traceback): | |
|
381 | if value is not None: | |||
|
382 | # If an error was raised, don't check anything else | |||
|
383 | return False | |||
378 | self.tee.flush() |
|
384 | self.tee.flush() | |
379 | setattr(sys, self.channel, self.orig_stream) |
|
385 | setattr(sys, self.channel, self.orig_stream) | |
380 | printed = self.buffer.getvalue() |
|
386 | printed = self.buffer.getvalue() |
General Comments 0
You need to be logged in to leave comments.
Login now