mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 18:24:44 +00:00
parent
b8dec67a4f
commit
20e746ac92
2 changed files with 36 additions and 0 deletions
|
|
@ -27,6 +27,9 @@ def get_write_and_truncate_functions(output):
|
|||
def truncate():
|
||||
with open(output, 'w') as output_file:
|
||||
pass
|
||||
elif callable(output):
|
||||
write = output
|
||||
truncate = None
|
||||
else:
|
||||
assert isinstance(output, utils.WritableStream)
|
||||
def write(s):
|
||||
|
|
|
|||
|
|
@ -43,6 +43,39 @@ def test_string_io():
|
|||
)
|
||||
|
||||
|
||||
|
||||
def test_callable():
|
||||
string_io = io.StringIO()
|
||||
|
||||
def write(msg):
|
||||
string_io.write(msg)
|
||||
|
||||
@pysnooper.snoop(write)
|
||||
def my_function(foo):
|
||||
x = 7
|
||||
y = 8
|
||||
return y + x
|
||||
|
||||
result = my_function('baba')
|
||||
assert result == 15
|
||||
output = string_io.getvalue()
|
||||
assert_output(
|
||||
output,
|
||||
(
|
||||
VariableEntry('foo', value_regex="u?'baba'"),
|
||||
CallEntry('def my_function(foo):'),
|
||||
LineEntry('x = 7'),
|
||||
VariableEntry('x', '7'),
|
||||
LineEntry('y = 8'),
|
||||
VariableEntry('y', '8'),
|
||||
LineEntry('return y + x'),
|
||||
ReturnEntry('return y + x'),
|
||||
ReturnValueEntry('15'),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
||||
def test_variables():
|
||||
|
||||
class Foo(object):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue