This commit is contained in:
Ram Rachum 2019-04-22 15:10:34 +03:00
parent 6e3d797be3
commit 15555ed760
2 changed files with 29 additions and 1 deletions

View file

@ -23,7 +23,7 @@ def get_write_function(output):
stderr.write(s)
elif isinstance(output, (pycompat.PathLike, str)):
def write(s):
with open(output_path, 'a') as output_file:
with open(output, 'a') as output_file:
output_file.write(s)
else:
assert isinstance(output, utils.WritableStream)

View file

@ -7,6 +7,7 @@ import abc
from python_toolbox import caching
from python_toolbox import sys_tools
from python_toolbox import temp_file_tools
import pysnooper
@ -169,3 +170,30 @@ def test_method_and_prefix():
),
prefix='ZZZ'
)
def test_file_output():
with temp_file_tools.create_temp_folder(prefix='pysnooper') as folder:
path = folder / 'foo.log'
@pysnooper.snoop(str(path))
def my_function(foo):
x = 7
y = 8
return y + x
result = my_function('baba')
assert result == 15
output = path.open().read()
assert_output(
output,
(
VariableEntry('foo', value_regex="u?'baba'"),
CallEntry(),
LineEntry('x = 7'),
VariableEntry('x', '7'),
LineEntry('y = 8'),
VariableEntry('y', '8'),
LineEntry('return y + x'),
ReturnEntry('return y + x'),
)
)