mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-07-25 11:54:07 +00:00
Fix #2
This commit is contained in:
parent
6e3d797be3
commit
15555ed760
2 changed files with 29 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue