Show More
@@ -51,24 +51,24 b' def recursionlimit(frames):' | |||
|
51 | 51 | class ChangedPyFileTest(unittest.TestCase): |
|
52 | 52 | def test_changing_py_file(self): |
|
53 | 53 | """Traceback produced if the line where the error occurred is missing? |
|
54 | ||
|
54 | ||
|
55 | 55 | https://github.com/ipython/ipython/issues/1456 |
|
56 | 56 | """ |
|
57 | 57 | with TemporaryDirectory() as td: |
|
58 | 58 | fname = os.path.join(td, "foo.py") |
|
59 | 59 | with open(fname, "w", encoding="utf-8") as f: |
|
60 | 60 | f.write(file_1) |
|
61 | ||
|
61 | ||
|
62 | 62 | with prepended_to_syspath(td): |
|
63 | 63 | ip.run_cell("import foo") |
|
64 | ||
|
64 | ||
|
65 | 65 | with tt.AssertPrints("ZeroDivisionError"): |
|
66 | 66 | ip.run_cell("foo.f()") |
|
67 | ||
|
67 | ||
|
68 | 68 | # Make the file shorter, so the line of the error is missing. |
|
69 | 69 | with open(fname, "w", encoding="utf-8") as f: |
|
70 | 70 | f.write(file_2) |
|
71 | ||
|
71 | ||
|
72 | 72 | # For some reason, this was failing on the *second* call after |
|
73 | 73 | # changing the file, so we call f() twice. |
|
74 | 74 | with tt.AssertNotPrints("Internal Python error", channel='stderr'): |
@@ -92,27 +92,27 b' class NonAsciiTest(unittest.TestCase):' | |||
|
92 | 92 | fname = os.path.join(td, u"fooΓ©.py") |
|
93 | 93 | with open(fname, "w", encoding="utf-8") as f: |
|
94 | 94 | f.write(file_1) |
|
95 | ||
|
95 | ||
|
96 | 96 | with prepended_to_syspath(td): |
|
97 | 97 | ip.run_cell("import foo") |
|
98 | ||
|
98 | ||
|
99 | 99 | with tt.AssertPrints("ZeroDivisionError"): |
|
100 | 100 | ip.run_cell("foo.f()") |
|
101 | ||
|
101 | ||
|
102 | 102 | def test_iso8859_5(self): |
|
103 | 103 | with TemporaryDirectory() as td: |
|
104 | 104 | fname = os.path.join(td, 'dfghjkl.py') |
|
105 | 105 | |
|
106 | 106 | with io.open(fname, 'w', encoding='iso-8859-5') as f: |
|
107 | 107 | f.write(iso_8859_5_file) |
|
108 | ||
|
108 | ||
|
109 | 109 | with prepended_to_syspath(td): |
|
110 | 110 | ip.run_cell("from dfghjkl import fail") |
|
111 | ||
|
111 | ||
|
112 | 112 | with tt.AssertPrints("ZeroDivisionError"): |
|
113 | 113 | with tt.AssertPrints(u'Π΄Π±ΠΠ', suppress=False): |
|
114 | 114 | ip.run_cell('fail()') |
|
115 | ||
|
115 | ||
|
116 | 116 | def test_nonascii_msg(self): |
|
117 | 117 | cell = u"raise Exception('Γ©')" |
|
118 | 118 | expected = u"Exception('Γ©')" |
@@ -167,12 +167,12 b' class IndentationErrorTest(unittest.TestCase):' | |||
|
167 | 167 | with tt.AssertPrints("IndentationError"): |
|
168 | 168 | with tt.AssertPrints("zoon()", suppress=False): |
|
169 | 169 | ip.run_cell(indentationerror_file) |
|
170 | ||
|
170 | ||
|
171 | 171 | with TemporaryDirectory() as td: |
|
172 | 172 | fname = os.path.join(td, "foo.py") |
|
173 | 173 | with open(fname, "w", encoding="utf-8") as f: |
|
174 | 174 | f.write(indentationerror_file) |
|
175 | ||
|
175 | ||
|
176 | 176 | with tt.AssertPrints("IndentationError"): |
|
177 | 177 | with tt.AssertPrints("zoon()", suppress=False): |
|
178 | 178 | ip.magic('run %s' % fname) |
@@ -591,7 +591,7 b' class ListTB(TBTools):' | |||
|
591 | 591 | """ |
|
592 | 592 | |
|
593 | 593 | Colors = self.Colors |
|
594 | list = [] | |
|
594 | output_list = [] | |
|
595 | 595 | for ind, (filename, lineno, name, line) in enumerate(extracted_list): |
|
596 | 596 | normalCol, nameCol, fileCol, lineCol = ( |
|
597 | 597 | # Emphasize the last entry |
@@ -609,9 +609,9 b' class ListTB(TBTools):' | |||
|
609 | 609 | item += "\n" |
|
610 | 610 | if line: |
|
611 | 611 | item += f"{lineCol} {line.strip()}{normalCol}\n" |
|
612 | list.append(item) | |
|
612 | output_list.append(item) | |
|
613 | 613 | |
|
614 | return list | |
|
614 | return output_list | |
|
615 | 615 | |
|
616 | 616 | def _format_exception_only(self, etype, value): |
|
617 | 617 | """Format the exception part of a traceback. |
@@ -628,11 +628,11 b' class ListTB(TBTools):' | |||
|
628 | 628 | """ |
|
629 | 629 | have_filedata = False |
|
630 | 630 | Colors = self.Colors |
|
631 | list = [] | |
|
631 | output_list = [] | |
|
632 | 632 | stype = py3compat.cast_unicode(Colors.excName + etype.__name__ + Colors.Normal) |
|
633 | 633 | if value is None: |
|
634 | 634 | # Not sure if this can still happen in Python 2.6 and above |
|
635 |
list.append(stype + |
|
|
635 | output_list.append(stype + "\n") | |
|
636 | 636 | else: |
|
637 | 637 | if issubclass(etype, SyntaxError): |
|
638 | 638 | have_filedata = True |
@@ -643,7 +643,7 b' class ListTB(TBTools):' | |||
|
643 | 643 | else: |
|
644 | 644 | lineno = "unknown" |
|
645 | 645 | textline = "" |
|
646 | list.append( | |
|
646 | output_list.append( | |
|
647 | 647 | "%s %s%s\n" |
|
648 | 648 | % ( |
|
649 | 649 | Colors.normalEm, |
@@ -663,31 +663,33 b' class ListTB(TBTools):' | |||
|
663 | 663 | i = 0 |
|
664 | 664 | while i < len(textline) and textline[i].isspace(): |
|
665 | 665 | i += 1 |
|
666 |
list.append( |
|
|
667 |
|
|
|
668 | Colors.Normal)) | |
|
666 | output_list.append( | |
|
667 | "%s %s%s\n" % (Colors.line, textline.strip(), Colors.Normal) | |
|
668 | ) | |
|
669 | 669 | if value.offset is not None: |
|
670 | 670 | s = ' ' |
|
671 | 671 | for c in textline[i:value.offset - 1]: |
|
672 | 672 | if c.isspace(): |
|
673 | 673 | s += c |
|
674 | 674 | else: |
|
675 |
s += |
|
|
676 |
list.append( |
|
|
677 |
|
|
|
675 | s += " " | |
|
676 | output_list.append( | |
|
677 | "%s%s^%s\n" % (Colors.caret, s, Colors.Normal) | |
|
678 | ) | |
|
678 | 679 | |
|
679 | 680 | try: |
|
680 | 681 | s = value.msg |
|
681 | 682 | except Exception: |
|
682 | 683 | s = self._some_str(value) |
|
683 | 684 | if s: |
|
684 | list.append('%s%s:%s %s\n' % (stype, Colors.excName, | |
|
685 | Colors.Normal, s)) | |
|
685 | output_list.append( | |
|
686 | "%s%s:%s %s\n" % (stype, Colors.excName, Colors.Normal, s) | |
|
687 | ) | |
|
686 | 688 | else: |
|
687 |
list.append( |
|
|
689 | output_list.append("%s\n" % stype) | |
|
688 | 690 | |
|
689 | 691 | # PEP-678 notes |
|
690 | list.extend(f"{x}\n" for x in getattr(value, "__notes__", [])) | |
|
692 | output_list.extend(f"{x}\n" for x in getattr(value, "__notes__", [])) | |
|
691 | 693 | |
|
692 | 694 | # sync with user hooks |
|
693 | 695 | if have_filedata: |
@@ -695,7 +697,7 b' class ListTB(TBTools):' | |||
|
695 | 697 | if ipinst is not None: |
|
696 | 698 | ipinst.hooks.synchronize_with_editor(value.filename, value.lineno, 0) |
|
697 | 699 | |
|
698 | return list | |
|
700 | return output_list | |
|
699 | 701 | |
|
700 | 702 | def get_exception_only(self, etype, value): |
|
701 | 703 | """Only print the exception type and message, without a traceback. |
@@ -1012,6 +1014,7 b' class VerboseTB(TBTools):' | |||
|
1012 | 1014 | etype, evalue = str, sys.exc_info()[:2] |
|
1013 | 1015 | etype_str, evalue_str = map(str, (etype, evalue)) |
|
1014 | 1016 | |
|
1017 | # PEP-678 notes | |
|
1015 | 1018 | notes = getattr(evalue, "__notes__", []) |
|
1016 | 1019 | if not isinstance(notes, Sequence) or isinstance(notes, (str, bytes)): |
|
1017 | 1020 | notes = [_safe_string(notes, "__notes__", func=repr)] |
General Comments 0
You need to be logged in to leave comments.
Login now