MCPcopy
hub / github.com/raiden-network/raiden / check_nested_attrs

Function check_nested_attrs

raiden/tests/utils/events.py:44–70  ·  view source on GitHub ↗

Checks the attributes from `item` match the values defined in `attributes`. >>> from collections import namedtuple >>> A = namedtuple('A', 'a') >>> B = namedtuple('B', 'b') >>> d = {'a': 1} >>> check_nested_attrs(A(1), {'a': 1}) True >>> check_nested_attrs(A(B(1)), {'a':

(item: Any, attributes: Mapping)

Source from the content-addressed store, hash-verified

42
43
44def check_nested_attrs(item: Any, attributes: Mapping) -> bool:
45 """Checks the attributes from `item` match the values defined in `attributes`.
46
47 >>> from collections import namedtuple
48 >>> A = namedtuple('A', 'a')
49 >>> B = namedtuple('B', 'b')
50 >>> d = {'a': 1}
51 >>> check_nested_attrs(A(1), {'a': 1})
52 True
53 >>> check_nested_attrs(A(B(1)), {'a': {'b': 1}})
54 True
55 >>> check_nested_attrs(A(1), {'a': 2})
56 False
57 >>> check_nested_attrs(A(1), {'b': 1})
58 False
59 """
60 for name, value in attributes.items():
61 item_value = getattr(item, name, NOVALUE)
62
63 if isinstance(value, Mapping):
64 if not check_nested_attrs(item_value, value):
65 return False
66
67 elif item_value != value:
68 return False
69
70 return True
71
72
73def search_for_item(

Callers 4

on_messagesMethod · 0.90
on_raiden_eventsMethod · 0.90
search_for_itemFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected