mirror of https://github.com/cool-RR/PySnooper.git
Support single tuple to `custom_repr`, fix #144
This commit is contained in:
parent
81868cd0ba
commit
814abc34a0
|
@ -214,6 +214,9 @@ class Tracer:
|
|||
self.target_codes = set()
|
||||
self.target_frames = set()
|
||||
self.thread_local = threading.local()
|
||||
if len(custom_repr) == 2 and not all(isinstance(x,
|
||||
pycompat.collections_abc.Iterable) for x in custom_repr):
|
||||
custom_repr = (custom_repr,)
|
||||
self.custom_repr = custom_repr
|
||||
|
||||
def __call__(self, function):
|
||||
|
|
|
@ -1174,6 +1174,30 @@ def test_custom_repr():
|
|||
)
|
||||
)
|
||||
|
||||
def test_custom_repr_single():
|
||||
string_io = io.StringIO()
|
||||
|
||||
@pysnooper.snoop(string_io, custom_repr=(list, lambda l: 'foofoo!'))
|
||||
def sum_to_x(x):
|
||||
l = list(range(x))
|
||||
return 7
|
||||
|
||||
result = sum_to_x(10000)
|
||||
|
||||
output = string_io.getvalue()
|
||||
assert_output(
|
||||
output,
|
||||
(
|
||||
VariableEntry('x', '10000'),
|
||||
CallEntry(),
|
||||
LineEntry(),
|
||||
VariableEntry('l', 'foofoo!'),
|
||||
LineEntry(),
|
||||
ReturnEntry(),
|
||||
ReturnValueEntry('7'),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_disable():
|
||||
string_io = io.StringIO()
|
||||
|
|
Loading…
Reference in New Issue