def test_find_iter_item(): class Foo: x = 123 y = 234 z = 345 class Bar: x = 345 y = 123 z = 234 class Baz: x = 345 y = 234 z = 123 uut = Foo config = make_default_config() config['match']['target'] = "attr" config['match'][ 'expression'] = "lambda value, name: name == 'z' and value == 123" path, match = digitout_silent(uut, config) assert path == "target.Baz.z" assert match['value'] == 123
def test_find_iter_item(): sentinel = object() uut = [{'x': 123, 'y': 234}, {'a': sentinel, 'b': 456}] config = make_default_config() config['match']['expression'] = 'lambda value: value == sentinel' path, match = digitout_silent(uut, config, locals()) assert path == "list(target)[1]['a']" assert match['value'] == sentinel
def test_find_iter_item(): uut = [{'a': 123, 'b': 234}, {'a': 345, 'b': 456}] config = make_default_config() config['match']['target'] = "item" config['match'][ 'expression'] = "lambda value, key: key == 'a' and value == 345" path, match = digitout_silent(uut, config) assert path == "list(target)[1]['a']" assert match['value'] == 345
def test_find_item_iter(): uut = {'a': [123, 234, 345], 'b': [123, 345, 234], 'c': [234, 345, 123]} config = make_default_config() config['match']['target'] = "iter" config['match'][ 'expression'] = "lambda value, index: index > 1 and value == 123" path, match = digitout_silent(uut, config) assert path == "list(target['c'])[2]" assert match['value'] == 123
def test_find_iter_key(): sentinel = object() uut = {sentinel: 345, 'b': 456} config = make_default_config() config['match']['expression'] = 'lambda value: value == sentinel' config['traversal']['iter']['inspect'] = False config['traversal']['item']['inspect_keys'] = True path, match = digitout_silent(uut, config, locals()) assert path == "list(target.keys())[0]" assert match['value'] == sentinel
def test_find_cls_attr(): sentinel = object() class Uut: xyz = sentinel uut = Uut() config = make_default_config() config['match']['expression'] = 'lambda value: value == sentinel' path, match = digitout_silent(uut, config, locals()) assert path == "target.xyz" assert match['value'] == sentinel
def test_find_ret_val_ann(): sentinel = object() class Uut: def xx(self) -> sentinel: pass uut = Uut() config = make_default_config() config['match']['expression'] = 'lambda value: value == sentinel' path, match = digitout_silent(uut, config, locals()) assert path == "target.__class__.xx.__annotations__['return']" assert match['value'] == sentinel
def test_find_cls_call_attr(): sentinel = object() class Uut: def __init__(self): self.xyz = sentinel uut = Uut config = make_default_config() config['match']['expression'] = 'lambda value: value == sentinel' config['traversal']['call']['skip_classes'] = False path, match = digitout_silent(uut, config, locals()) assert path == "target().xyz" assert match['value'] == sentinel