review fixes:
* change 'code' attr to 'snippet_code'; * change 'Executed code' header; * code changed to for-enumerate/oneline-if idioms; * add python stacktrace printing tests;
This commit is contained in:
parent
3accb5cb44
commit
47a3d18629
@ -68,21 +68,17 @@ Following is the full stack trace:
|
||||
"""
|
||||
|
||||
msg += traceback.format_exc()
|
||||
if hasattr(e, 'code'):
|
||||
if hasattr(e, 'snippet_code'):
|
||||
_, _, tb = sys.exc_info()
|
||||
tb_top = traceback.extract_tb(tb)[-1]
|
||||
msg += "\nFollowing is the full executed code:\n"
|
||||
lines = e.code.split("\n")
|
||||
number = 1
|
||||
for line in lines:
|
||||
msg += "\nExecuted snippet code:\n"
|
||||
lines = e.snippet_code.split("\n")
|
||||
for number, line in enumerate(lines, 1):
|
||||
msg += str(number).rjust(3)
|
||||
prefix = ""
|
||||
if line != "":
|
||||
prefix = " "
|
||||
prefix = " " if line else ""
|
||||
if tb_top[1] == number:
|
||||
prefix = " > "
|
||||
msg += prefix + line + "\n"
|
||||
number += 1
|
||||
|
||||
# Vim sends no WinLeave msg here.
|
||||
self._leaving_buffer() # pylint:disable=protected-access
|
||||
|
@ -266,12 +266,11 @@ class PythonCode(NoneditableTextObject):
|
||||
})
|
||||
self._snip._reset(ct) # pylint:disable=protected-access
|
||||
|
||||
|
||||
for code in self._codes:
|
||||
try:
|
||||
exec(code, self._locals) # pylint:disable=exec-used
|
||||
except Exception as e:
|
||||
e.code = code
|
||||
e.snippet_code = code
|
||||
raise
|
||||
|
||||
rv = as_unicode(
|
||||
|
@ -239,3 +239,27 @@ endsnippet
|
||||
"""}
|
||||
keys = 'ab' + EX
|
||||
wanted = 'x first a bob b y'
|
||||
|
||||
|
||||
class ParseSnippets_PrintPythonStacktrace(_VimTest):
|
||||
files = { 'us/all.snippets': r"""
|
||||
snippet test
|
||||
`!p abc()`
|
||||
endsnippet
|
||||
"""}
|
||||
keys = 'test' + EX
|
||||
wanted = keys
|
||||
expected_error = " > abc"
|
||||
|
||||
|
||||
class ParseSnippets_PrintPythonStacktraceMultiline(_VimTest):
|
||||
files = { 'us/all.snippets': r"""
|
||||
snippet test
|
||||
`!p if True:
|
||||
qwe()`
|
||||
endsnippet
|
||||
"""}
|
||||
keys = 'test' + EX
|
||||
wanted = keys
|
||||
expected_error = " > \s+qwe"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user