mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 02:14:04 +00:00
remove setup function and description
This commit is contained in:
parent
a807989923
commit
b4c8c16ed9
4 changed files with 5 additions and 69 deletions
17
README.md
17
README.md
|
|
@ -207,22 +207,7 @@ Exclude specific keys/attributes/indices with the `exclude` parameter, e.g. `Att
|
|||
|
||||
Add a slice after `Indices` to only see the values within that slice, e.g. `Indices('z')[-3:]`.
|
||||
|
||||
`PYSNOOPER_DISABLED` as an environment variable, can be used to activate or deactivate pysnooner. Pysnooper is deactived by setting the parameter to a non-empty value , and actived by default.
|
||||
|
||||
You can use `snoop.setup()` method to configure and get a new snoop object, then use it globally or in scope. Any parameters passing to `setup()` method should be supported by snoop.
|
||||
```python
|
||||
import pysnooper.snoop
|
||||
|
||||
# use my_snoop to debug. my_snoop will always be enabled, stderr will redirect output to a file
|
||||
my_snoop = snoop.setup(output='/my/log/file.log', disable=False)
|
||||
|
||||
@my_snoop()
|
||||
def foo():
|
||||
x = 5
|
||||
y = 10
|
||||
return x + y
|
||||
```
|
||||
Notice that `PYSNOOPER_DISABLED` will be invalid if `disable` parameter is specified in `setup()`
|
||||
`PYSNOOPER_DISABLED` as an environment variable, can be used to activate or deactivate pysnooner. Pysnooper is deactivated by setting the parameter to a non-empty value, and active by default.
|
||||
|
||||
# Contribute #
|
||||
|
||||
|
|
|
|||
|
|
@ -47,11 +47,6 @@ try:
|
|||
except AttributeError:
|
||||
iscoroutinefunction = lambda whatever: False # Lolz
|
||||
|
||||
try:
|
||||
getfullargspec = inspect.getfullargspec
|
||||
except AttributeError:
|
||||
getfullargspec = inspect.getargspec
|
||||
|
||||
|
||||
if PY3:
|
||||
string_types = (str,)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class FileWriter(object):
|
|||
|
||||
|
||||
thread_global = threading.local()
|
||||
|
||||
DISABLED = os.getenv("PYSNOOPER_DISABLED", "")
|
||||
|
||||
class Tracer:
|
||||
'''
|
||||
|
|
@ -195,7 +195,6 @@ class Tracer:
|
|||
overwrite=False,
|
||||
thread_info=False,
|
||||
custom_repr=(),
|
||||
disable=None,
|
||||
):
|
||||
self._write = get_write_function(output, overwrite)
|
||||
|
||||
|
|
@ -216,10 +215,9 @@ class Tracer:
|
|||
self.target_frames = set()
|
||||
self.thread_local = threading.local()
|
||||
self.custom_repr = custom_repr
|
||||
self.disable = os.getenv("PYSNOOPER_DISABLED", "") if disable is None else disable
|
||||
|
||||
def __call__(self, function):
|
||||
if self.disable:
|
||||
if DISABLED:
|
||||
return function
|
||||
self.target_codes.add(function.__code__)
|
||||
|
||||
|
|
@ -256,7 +254,7 @@ class Tracer:
|
|||
self._write(s)
|
||||
|
||||
def __enter__(self):
|
||||
if self.disable:
|
||||
if DISABLED:
|
||||
return
|
||||
calling_frame = inspect.currentframe().f_back
|
||||
if not self._is_internal_frame(calling_frame):
|
||||
|
|
@ -268,7 +266,7 @@ class Tracer:
|
|||
sys.settrace(self.trace)
|
||||
|
||||
def __exit__(self, exc_type, exc_value, exc_traceback):
|
||||
if self.disable:
|
||||
if DISABLED:
|
||||
return
|
||||
stack = self.thread_local.original_trace_functions
|
||||
sys.settrace(stack.pop())
|
||||
|
|
@ -408,9 +406,3 @@ class Tracer:
|
|||
format(**locals()))
|
||||
|
||||
return self.trace
|
||||
|
||||
@classmethod
|
||||
def setup(cls, **kwargs):
|
||||
if not (set(pycompat.getfullargspec(cls.__init__).args) > set(kwargs.keys())):
|
||||
raise Exception('The parameters passed to setup contain non-snoop parameters')
|
||||
return functools.partial(cls, **kwargs)
|
||||
|
|
|
|||
|
|
@ -1191,39 +1191,3 @@ def test_activate_deactivate_snoop():
|
|||
|
||||
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