def test_nonstrict_map_with_dict_not_throws(): tr = Trict(base_dict()) mapper = { 'newkey': [['none', 'of', 'these'], ['are', 'in', 'there']], 'othernewkey': ['and.these.are', 'not.either'] } mapped = tr.map_with_dict(mapper) assert mapped == {'newkey': None, 'othernewkey': None}
def test_map_with_dict_maps(): tr = Trict(base_dict()) mapper = { 'newkey': [ 'user.noninformation.nonattribute', 'user.information.another_attribute' ], 'othernewkey': [['user', 'noninformation'], ['user', 'information']] } assert tr.map_with_dict(mapper) == { 'newkey': 'secondnugget', 'othernewkey': { 'attribute': 'infonugget', 'another_attribute': 'secondnugget' }, }
def test_map_with_dict_throws(): tr = Trict(base_dict()) mapper = {'newkey': [['none', 'of', 'these'], ['are', 'in', 'there']]} with pytest.raises(KeyError): tr.map_with_dict(mapper, strict=True)