Merge pull request #3681 from tadeoos/980-fix-truncated-locals-in-verbose

Fix truncated locals in verbose mode
This commit is contained in:
Bruno Oliveira 2018-07-15 14:43:15 -03:00 committed by GitHub
commit db33f03c15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 1 deletions

View File

@ -192,6 +192,7 @@ Stefan Zimmermann
Stefano Taschini
Steffen Allner
Stephan Obermann
Tadek Teleżyński
Tarcisio Fischer
Tareq Alayan
Ted Xiao

1
changelog/980.bugfix.rst Normal file
View File

@ -0,0 +1 @@
Fix truncated locals output in verbose mode.

View File

@ -1,5 +1,6 @@
from __future__ import absolute_import, division, print_function
import inspect
import pprint
import sys
import traceback
from inspect import CO_VARARGS, CO_VARKEYWORDS
@ -448,6 +449,7 @@ class ExceptionInfo(object):
abspath=False,
tbfilter=True,
funcargs=False,
truncate_locals=True,
):
""" return str()able representation of this exception info.
showlocals: show locals per traceback entry
@ -472,6 +474,7 @@ class ExceptionInfo(object):
abspath=abspath,
tbfilter=tbfilter,
funcargs=funcargs,
truncate_locals=truncate_locals,
)
return fmt.repr_excinfo(self)
@ -511,6 +514,7 @@ class FormattedExcinfo(object):
abspath = attr.ib(default=True)
tbfilter = attr.ib(default=True)
funcargs = attr.ib(default=False)
truncate_locals = attr.ib(default=True)
astcache = attr.ib(default=attr.Factory(dict), init=False, repr=False)
def _getindent(self, source):
@ -593,7 +597,10 @@ class FormattedExcinfo(object):
# This formatting could all be handled by the
# _repr() function, which is only reprlib.Repr in
# disguise, so is very configurable.
str_repr = self._saferepr(value)
if self.truncate_locals:
str_repr = self._saferepr(value)
else:
str_repr = pprint.pformat(value)
# if len(str_repr) < 70 or not isinstance(value,
# (list, tuple, dict)):
lines.append("%-10s = %s" % (name, str_repr))

View File

@ -287,6 +287,11 @@ class Node(object):
else:
style = "long"
if self.config.option.verbose > 1:
truncate_locals = False
else:
truncate_locals = True
try:
os.getcwd()
abspath = False
@ -299,6 +304,7 @@ class Node(object):
showlocals=self.config.option.showlocals,
style=style,
tbfilter=tbfilter,
truncate_locals=truncate_locals,
)
repr_failure = _repr_failure_py

View File

@ -579,6 +579,18 @@ raise ValueError()
assert reprlocals.lines[2] == "y = 5"
assert reprlocals.lines[3] == "z = 7"
def test_repr_local_truncated(self):
loc = {"l": [i for i in range(10)]}
p = FormattedExcinfo(showlocals=True)
truncated_reprlocals = p.repr_locals(loc)
assert truncated_reprlocals.lines
assert truncated_reprlocals.lines[0] == "l = [0, 1, 2, 3, 4, 5, ...]"
q = FormattedExcinfo(showlocals=True, truncate_locals=False)
full_reprlocals = q.repr_locals(loc)
assert full_reprlocals.lines
assert full_reprlocals.lines[0] == "l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
def test_repr_tracebackentry_lines(self, importasmod):
mod = importasmod(
"""