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