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)
| 42 | |
| 43 | |
| 44 | def 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 | |
| 73 | def search_for_item( |
no outgoing calls
no test coverage detected