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_break_on_setattr_condition():
def mycond(obj, value):
return value == 42
class Foo(object):
pass
# we don't use a class decorator to keep 2.5 compatibility
Foo = pdbpp.break_on_setattr('x', condition=mycond, Pdb=PdbTest)(Foo)
def fn():
obj = Foo()
obj.x = 0
obj.x = 42
return obj.x
check(fn, """
[NUM] > .*fn()
def test_break_on_setattr_without_hidden_frames():
class PdbWithConfig(PdbTest):
def __init__(self, *args, **kwargs):
class Config(ConfigTest):
enable_hidden_frames = False
super(PdbWithConfig, self).__init__(*args, Config=Config, **kwargs)
class Foo(object):
pass
Foo = pdbpp.break_on_setattr('x', Pdb=PdbWithConfig)(Foo)
def fn():
obj = Foo()
obj.x = 0
return obj.x
check(fn, """
[NUM] > .*fn()
def fn():
a = Foo()
b = Foo()
def break_if_a(obj, value):
return obj is a
pdbpp.break_on_setattr("bar", condition=break_if_a, Pdb=PdbTest)(Foo)
b.bar = 10
a.bar = 42
def test_break_on_setattr():
# we don't use a class decorator to keep 2.5 compatibility
class Foo(object):
pass
Foo = pdbpp.break_on_setattr('x', Pdb=PdbTest)(Foo)
def fn():
obj = Foo()
obj.x = 0
return obj.x
check(fn, """
[NUM] > .*fn()
def test_break_on_setattr_overridden():
# we don't use a class decorator to keep 2.5 compatibility
class Foo(object):
def __setattr__(self, attr, value):
object.__setattr__(self, attr, value+1)
Foo = pdbpp.break_on_setattr('x', Pdb=PdbTest)(Foo)
def fn():
obj = Foo()
obj.y = 41
obj.x = 0
return obj.x
check(fn, """
[NUM] > .*fn()