##// END OF EJS Templates
Add line number next to the file in the traceback...
Matthias Bussonnier -
r27356:e023dcb2 merge
parent child Browse files
Show More
@@ -419,9 +419,9 b' class TestCompleter(unittest.TestCase):'
419 with provisionalcompleter():
419 with provisionalcompleter():
420 ip.Completer.use_jedi = jedi_status
420 ip.Completer.use_jedi = jedi_status
421 matches = c.all_completions("TestCl")
421 matches = c.all_completions("TestCl")
422 assert matches == ['TestClass'], jedi_status
422 assert matches == ["TestClass"], (jedi_status, matches)
423 matches = c.all_completions("TestClass.")
423 matches = c.all_completions("TestClass.")
424 assert len(matches) > 2, jedi_status
424 assert len(matches) > 2, (jedi_status, matches)
425 matches = c.all_completions("TestClass.a")
425 matches = c.all_completions("TestClass.a")
426 assert matches == ['TestClass.a', 'TestClass.a1'], jedi_status
426 assert matches == ['TestClass.a', 'TestClass.a1'], jedi_status
427
427
@@ -45,11 +45,11 b' def doctest_tb_plain():'
45
45
46 In [19]: run simpleerr.py
46 In [19]: run simpleerr.py
47 Traceback (most recent call last):
47 Traceback (most recent call last):
48 ...line ..., in <module>
48 File ...:... in <module>
49 bar(mode)
49 bar(mode)
50 ...line ..., in bar
50 File ...:... in bar
51 div0()
51 div0()
52 ...line ..., in div0
52 File ...:... in div0
53 x/y
53 x/y
54 ZeroDivisionError: ...
54 ZeroDivisionError: ...
55 """
55 """
@@ -132,13 +132,13 b' def doctest_tb_sysexit():'
132
132
133 In [20]: %tb
133 In [20]: %tb
134 Traceback (most recent call last):
134 Traceback (most recent call last):
135 File ..., in execfile
135 File ...:... in execfile
136 exec(compiler(f.read(), fname, "exec"), glob, loc)
136 exec(compiler(f.read(), fname, "exec"), glob, loc)
137 File ..., in <module>
137 File ...:... in <module>
138 bar(mode)
138 bar(mode)
139 File ..., in bar
139 File ...:... in bar
140 sysexit(stat, mode)
140 sysexit(stat, mode)
141 File ..., in sysexit
141 File ...:... in sysexit
142 raise SystemExit(stat, f"Mode = {mode}")
142 raise SystemExit(stat, f"Mode = {mode}")
143 SystemExit: (2, 'Mode = exit')
143 SystemExit: (2, 'Mode = exit')
144
144
@@ -188,10 +188,6 b' se_file_2 = """7/'
188 """
188 """
189
189
190 class SyntaxErrorTest(unittest.TestCase):
190 class SyntaxErrorTest(unittest.TestCase):
191 def test_syntaxerror_without_lineno(self):
192 with tt.AssertNotPrints("TypeError"):
193 with tt.AssertPrints("line unknown"):
194 ip.run_cell("raise SyntaxError()")
195
191
196 def test_syntaxerror_no_stacktrace_at_compile_time(self):
192 def test_syntaxerror_no_stacktrace_at_compile_time(self):
197 syntax_error_at_compile_time = """
193 syntax_error_at_compile_time = """
@@ -169,7 +169,7 b' def _format_traceback_lines(lines, Colors, has_colors, lvals):'
169 return res
169 return res
170
170
171
171
172 def _format_filename(file, ColorFilename, ColorNormal):
172 def _format_filename(file, ColorFilename, ColorNormal, *, lineno=None):
173 """
173 """
174 Format filename lines with `In [n]` if it's the nth code cell or `File *.py` if it's a module.
174 Format filename lines with `In [n]` if it's the nth code cell or `File *.py` if it's a module.
175
175
@@ -185,14 +185,17 b' def _format_filename(file, ColorFilename, ColorNormal):'
185
185
186 if ipinst is not None and file in ipinst.compile._filename_map:
186 if ipinst is not None and file in ipinst.compile._filename_map:
187 file = "[%s]" % ipinst.compile._filename_map[file]
187 file = "[%s]" % ipinst.compile._filename_map[file]
188 tpl_link = "Input %sIn %%s%s" % (ColorFilename, ColorNormal)
188 tpl_link = f"Input {ColorFilename}In {{file}}{ColorNormal}"
189 else:
189 else:
190 file = util_path.compress_user(
190 file = util_path.compress_user(
191 py3compat.cast_unicode(file, util_path.fs_encoding)
191 py3compat.cast_unicode(file, util_path.fs_encoding)
192 )
192 )
193 tpl_link = "File %s%%s%s" % (ColorFilename, ColorNormal)
193 if lineno is None:
194 tpl_link = f"File {ColorFilename}{{file}}{ColorNormal}"
195 else:
196 tpl_link = f"File {ColorFilename}{{file}}:{{lineno}}{ColorNormal}"
194
197
195 return tpl_link % file
198 return tpl_link.format(file=file, lineno=lineno)
196
199
197 #---------------------------------------------------------------------------
200 #---------------------------------------------------------------------------
198 # Module classes
201 # Module classes
@@ -439,11 +442,10 b' class ListTB(TBTools):'
439 Colors = self.Colors
442 Colors = self.Colors
440 list = []
443 list = []
441 for filename, lineno, name, line in extracted_list[:-1]:
444 for filename, lineno, name, line in extracted_list[:-1]:
442 item = " %s, line %s%d%s, in %s%s%s\n" % (
445 item = " %s in %s%s%s\n" % (
443 _format_filename(filename, Colors.filename, Colors.Normal),
446 _format_filename(
444 Colors.lineno,
447 filename, Colors.filename, Colors.Normal, lineno=lineno
445 lineno,
448 ),
446 Colors.Normal,
447 Colors.name,
449 Colors.name,
448 name,
450 name,
449 Colors.Normal,
451 Colors.Normal,
@@ -453,12 +455,11 b' class ListTB(TBTools):'
453 list.append(item)
455 list.append(item)
454 # Emphasize the last entry
456 # Emphasize the last entry
455 filename, lineno, name, line = extracted_list[-1]
457 filename, lineno, name, line = extracted_list[-1]
456 item = "%s %s, line %s%d%s, in %s%s%s%s\n" % (
458 item = "%s %s in %s%s%s%s\n" % (
457 Colors.normalEm,
458 _format_filename(filename, Colors.filenameEm, Colors.normalEm),
459 Colors.linenoEm,
460 lineno,
461 Colors.normalEm,
459 Colors.normalEm,
460 _format_filename(
461 filename, Colors.filenameEm, Colors.normalEm, lineno=lineno
462 ),
462 Colors.nameEm,
463 Colors.nameEm,
463 name,
464 name,
464 Colors.normalEm,
465 Colors.normalEm,
@@ -501,14 +502,15 b' class ListTB(TBTools):'
501 lineno = "unknown"
502 lineno = "unknown"
502 textline = ""
503 textline = ""
503 list.append(
504 list.append(
504 "%s %s, line %s%s%s\n"
505 "%s %s%s\n"
505 % (
506 % (
506 Colors.normalEm,
507 Colors.normalEm,
507 _format_filename(
508 _format_filename(
508 value.filename, Colors.filenameEm, Colors.normalEm
509 value.filename,
510 Colors.filenameEm,
511 Colors.normalEm,
512 lineno=(None if lineno == "unknown" else lineno),
509 ),
513 ),
510 Colors.linenoEm,
511 lineno,
512 Colors.Normal,
514 Colors.Normal,
513 )
515 )
514 )
516 )
@@ -628,27 +630,35 b' class VerboseTB(TBTools):'
628 return ' %s[... skipping similar frames: %s]%s\n' % (
630 return ' %s[... skipping similar frames: %s]%s\n' % (
629 Colors.excName, frame_info.description, ColorsNormal)
631 Colors.excName, frame_info.description, ColorsNormal)
630
632
631 indent = ' ' * INDENT_SIZE
633 indent = " " * INDENT_SIZE
632 em_normal = '%s\n%s%s' % (Colors.valEm, indent, ColorsNormal)
634 em_normal = "%s\n%s%s" % (Colors.valEm, indent, ColorsNormal)
633 tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm,
635 tpl_call = f"in {Colors.vName}{{file}}{Colors.valEm}{{scope}}{ColorsNormal}"
634 ColorsNormal)
636 tpl_call_fail = "in %s%%s%s(***failed resolving arguments***)%s" % (
635 tpl_call_fail = 'in %s%%s%s(***failed resolving arguments***)%s' % \
637 Colors.vName,
636 (Colors.vName, Colors.valEm, ColorsNormal)
638 Colors.valEm,
637 tpl_name_val = '%%s %s= %%s%s' % (Colors.valEm, ColorsNormal)
639 ColorsNormal,
640 )
641 tpl_name_val = "%%s %s= %%s%s" % (Colors.valEm, ColorsNormal)
638
642
639 link = _format_filename(frame_info.filename, Colors.filenameEm, ColorsNormal)
643 link = _format_filename(
644 frame_info.filename,
645 Colors.filenameEm,
646 ColorsNormal,
647 lineno=frame_info.lineno,
648 )
640 args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame)
649 args, varargs, varkw, locals_ = inspect.getargvalues(frame_info.frame)
641
650
642 func = frame_info.executing.code_qualname()
651 func = frame_info.executing.code_qualname()
643 if func == '<module>':
652 if func == "<module>":
644 call = tpl_call % (func, '')
653 call = tpl_call.format(file=func, scope="")
645 else:
654 else:
646 # Decide whether to include variable details or not
655 # Decide whether to include variable details or not
647 var_repr = eqrepr if self.include_vars else nullrepr
656 var_repr = eqrepr if self.include_vars else nullrepr
648 try:
657 try:
649 call = tpl_call % (func, inspect.formatargvalues(args,
658 scope = inspect.formatargvalues(
650 varargs, varkw,
659 args, varargs, varkw, locals_, formatvalue=var_repr
651 locals_, formatvalue=var_repr))
660 )
661 call = tpl_call.format(file=func, scope=scope)
652 except KeyError:
662 except KeyError:
653 # This happens in situations like errors inside generator
663 # This happens in situations like errors inside generator
654 # expressions, where local variables are listed in the
664 # expressions, where local variables are listed in the
@@ -503,7 +503,7 b' def _check_all_skipped(test: "doctest.DocTest") -> None:'
503
503
504 all_skipped = all(x.options.get(doctest.SKIP, False) for x in test.examples)
504 all_skipped = all(x.options.get(doctest.SKIP, False) for x in test.examples)
505 if all_skipped:
505 if all_skipped:
506 pytest.skip("all tests skipped by +SKIP option")
506 pytest.skip("all docstests skipped by +SKIP option")
507
507
508
508
509 def _is_mocked(obj: object) -> bool:
509 def _is_mocked(obj: object) -> bool:
General Comments 0
You need to be logged in to leave comments. Login now