Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_predicate_q_deduplicate_callprinter():
out = repr(Q(CallPrinter(), action=CallPrinter()))
assert out.startswith('CallPrinter(')
@classmethod
def local_cm(cls, _):
pass
def local_m(self, _):
pass
local_dm = Desc(lf)
local_ddm = Desc(dlf)
global_dm = Desc(gf)
global_ddm = Desc(dgf)
buff = StringIO()
with trace(actions=[
hunter.CallPrinter(stream=buff),
lambda event: buff.write(
"{0.function}({1})|{2}|{0.kind}\n".format(
event,
event.locals.get('_'),
getattr(event.function_object, '__name__', 'missing')))
]):
gf(1)
dgf(2)
lf(3)
dlf(4)
Old.old_sm(5)
Old.old_cm(6)
Old().old_sm(7)
Old().old_cm(8)
Old().old_m(9)
New.new_sm(10)
def test_callprinter_indent(LineMatcher):
from sample6 import bar
out = StringIO()
with trace(action=CallPrinter(stream=out)):
bar()
lm = LineMatcher(out.getvalue().splitlines())
lm.fnmatch_lines([
"*sample6.py:1 call => bar()",
"*sample6.py:2 line foo()",
"*sample6.py:5 call => foo()",
"*sample6.py:6 line try:",
"*sample6.py:7 line asdf()",
"*sample6.py:16 call => asdf()",
"*sample6.py:17 line raise Exception()",
"*sample6.py:17 exception ! asdf: (<*Exception'>, Exception(), )",
"*sample6.py:17 return <= asdf: None",
"*sample6.py:7 exception ! foo: (<*Exception'>, Exception(), )",
"*sample6.py:8 line except:",
"*sample6.py:9 line pass",
def test_callprinter(LineMatcher):
out = StringIO()
with trace(action=CallPrinter(stream=out)):
foo = bar = lambda x: x
@foo
@bar
def foo():
return 1
foo()
lm = LineMatcher(out.getvalue().splitlines())
lm.fnmatch_lines([
'* call => (x=)',
'* line foo = bar = lambda x: x',
'* return <= : ',
'* call => (x=)',
'* line foo = bar = lambda x: x',
def test_clear_env_var(monkeypatch):
monkeypatch.setitem(os.environ, 'PYTHONHUNTER', '123')
assert os.environ.get('PYTHONHUNTER') == '123'
out = StringIO()
with trace(action=CallPrinter(stream=out), clear_env_var=True):
assert 'PYTHONHUNTER' not in os.environ
assert os.environ.get('PYTHONHUNTER') == None