Show More
@@ -1681,20 +1681,12 b' class InteractiveShell(SingletonConfigurable, Magic):' | |||
|
1681 | 1681 | sys.last_traceback = last_traceback |
|
1682 | 1682 | |
|
1683 | 1683 | if filename and etype is SyntaxError: |
|
1684 | # Work hard to stuff the correct filename in the exception | |
|
1685 | 1684 | try: |
|
1686 | msg, (dummy_filename, lineno, offset, line) = value | |
|
1685 | value.filename = filename | |
|
1687 | 1686 | except: |
|
1688 | 1687 | # Not the format we expect; leave it alone |
|
1689 | 1688 | pass |
|
1690 |
|
|
|
1691 | # Stuff in the right filename | |
|
1692 | try: | |
|
1693 | # Assume SyntaxError is a class exception | |
|
1694 | value = SyntaxError(msg, (filename, lineno, offset, line)) | |
|
1695 | except: | |
|
1696 | # If that failed, assume SyntaxError is a string | |
|
1697 | value = msg, (filename, lineno, offset, line) | |
|
1689 | ||
|
1698 | 1690 | stb = self.SyntaxTB.structured_traceback(etype, value, []) |
|
1699 | 1691 | self._showtraceback(etype, value, stb) |
|
1700 | 1692 |
@@ -548,44 +548,40 b' class ListTB(TBTools):' | |||
|
548 | 548 | have_filedata = False |
|
549 | 549 | Colors = self.Colors |
|
550 | 550 | list = [] |
|
551 | try: | |
|
552 | stype = Colors.excName + etype.__name__ + Colors.Normal | |
|
553 | except AttributeError: | |
|
554 | stype = etype # String exceptions don't get special coloring | |
|
551 | stype = Colors.excName + etype.__name__ + Colors.Normal | |
|
555 | 552 | if value is None: |
|
553 | # Not sure if this can still happen in Python 2.6 and above | |
|
556 | 554 | list.append( str(stype) + '\n') |
|
557 | 555 | else: |
|
558 | 556 | if etype is SyntaxError: |
|
559 |
|
|
|
560 | msg, (filename, lineno, offset, line) = value | |
|
561 | except: | |
|
562 | have_filedata = False | |
|
563 | else: | |
|
564 | have_filedata = True | |
|
565 | #print 'filename is',filename # dbg | |
|
566 | if not filename: filename = "<string>" | |
|
567 | list.append('%s File %s"%s"%s, line %s%d%s\n' % \ | |
|
568 | (Colors.normalEm, | |
|
569 | Colors.filenameEm, filename, Colors.normalEm, | |
|
570 | Colors.linenoEm, lineno, Colors.Normal )) | |
|
571 | if line is not None: | |
|
572 | i = 0 | |
|
573 | while i < len(line) and line[i].isspace(): | |
|
574 |
|
|
|
575 | list.append('%s %s%s\n' % (Colors.line, | |
|
576 |
|
|
|
577 |
|
|
|
578 |
|
|
|
579 |
s = ' |
|
|
580 | for c in line[i:offset-1]: | |
|
581 |
|
|
|
582 | s = s + c | |
|
583 | else: | |
|
584 | s = s + ' ' | |
|
585 | list.append('%s%s^%s\n' % (Colors.caret, s, | |
|
586 | Colors.Normal) ) | |
|
587 | value = msg | |
|
588 | s = self._some_str(value) | |
|
557 | have_filedata = True | |
|
558 | #print 'filename is',filename # dbg | |
|
559 | if not value.filename: value.filename = "<string>" | |
|
560 | list.append('%s File %s"%s"%s, line %s%d%s\n' % \ | |
|
561 | (Colors.normalEm, | |
|
562 | Colors.filenameEm, value.filename, Colors.normalEm, | |
|
563 | Colors.linenoEm, value.lineno, Colors.Normal )) | |
|
564 | if value.text is not None: | |
|
565 | i = 0 | |
|
566 | while i < len(value.text) and value.text[i].isspace(): | |
|
567 | i = i+1 | |
|
568 | list.append('%s %s%s\n' % (Colors.line, | |
|
569 | value.text.strip(), | |
|
570 | Colors.Normal)) | |
|
571 | if value.offset is not None: | |
|
572 | s = ' ' | |
|
573 | for c in value.text[i:value.offset-1]: | |
|
574 | if c.isspace(): | |
|
575 | s = s + c | |
|
576 | else: | |
|
577 | s = s + ' ' | |
|
578 | list.append('%s%s^%s\n' % (Colors.caret, s, | |
|
579 | Colors.Normal) ) | |
|
580 | ||
|
581 | try: | |
|
582 | s = value.msg | |
|
583 | except Exception: | |
|
584 | s = self._some_str(value) | |
|
589 | 585 | if s: |
|
590 | 586 | list.append('%s%s:%s %s\n' % (str(stype), Colors.excName, |
|
591 | 587 | Colors.Normal, s)) |
@@ -596,7 +592,7 b' class ListTB(TBTools):' | |||
|
596 | 592 | if have_filedata: |
|
597 | 593 | ipinst = ipapi.get() |
|
598 | 594 | if ipinst is not None: |
|
599 | ipinst.hooks.synchronize_with_editor(filename, lineno, 0) | |
|
595 | ipinst.hooks.synchronize_with_editor(value.filename, value.lineno, 0) | |
|
600 | 596 | |
|
601 | 597 | return list |
|
602 | 598 |
@@ -13,7 +13,6 b' import unittest' | |||
|
13 | 13 | |
|
14 | 14 | # IPython imports |
|
15 | 15 | from IPython.lib import irunner |
|
16 | from IPython.testing.decorators import known_failure_py3 | |
|
17 | 16 | from IPython.utils.py3compat import doctest_refactor_print |
|
18 | 17 | |
|
19 | 18 | # Testing code begins |
@@ -58,8 +57,6 b' class RunnerTestCase(unittest.TestCase):' | |||
|
58 | 57 | self.assert_(mismatch==0,'Number of mismatched lines: %s' % |
|
59 | 58 | mismatch) |
|
60 | 59 | |
|
61 | # The SyntaxError appears differently in Python 3, for some reason. | |
|
62 | @known_failure_py3 | |
|
63 | 60 | def testIPython(self): |
|
64 | 61 | """Test the IPython runner.""" |
|
65 | 62 | source = doctest_refactor_print(""" |
General Comments 0
You need to be logged in to leave comments.
Login now