mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 02:14:04 +00:00
add unittest for activate and setup snoop
This commit is contained in:
parent
08375e1a86
commit
f1582fc16c
1 changed files with 55 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ import io
|
|||
import textwrap
|
||||
import threading
|
||||
import types
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pysnooper.utils import truncate
|
||||
|
|
@ -1172,3 +1173,57 @@ def test_custom_repr():
|
|||
ReturnValueEntry('49995000'),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def test_activate_deactivate_snoop():
|
||||
string_io = io.StringIO()
|
||||
|
||||
def my_function(foo):
|
||||
x = 7
|
||||
y = 8
|
||||
return x + y
|
||||
|
||||
os.environ['PYSNOOPER_DISABLED'] = '1'
|
||||
with pysnooper.snoop():
|
||||
result = my_function('baba')
|
||||
output = string_io.getvalue()
|
||||
assert output == ""
|
||||
|
||||
os.environ['PYSNOOPER_DISABLED'] = ''
|
||||
test_string_io()
|
||||
|
||||
|
||||
def test_setup_snoop_global():
|
||||
my_snoop = pysnooper.snoop.setup(disable=False)
|
||||
os.environ['PYSNOOPER_DISABLED'] = '1'
|
||||
|
||||
@my_snoop()
|
||||
def my_function(foo):
|
||||
x = 7
|
||||
y = 8
|
||||
return y + x
|
||||
|
||||
with mini_toolbox.OutputCapturer(stdout=False,
|
||||
stderr=True) as output_capturer:
|
||||
result = my_function('baba')
|
||||
output = output_capturer.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_mismatch_parameters_in_setup():
|
||||
with pytest.raises(Exception, match='contain non-snoop parameters') as excinfo:
|
||||
my_snoop = pysnooper.snoop.setup(disabled=False)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue