def test_dig_through_dict(self): obj = Entity({ "a": 1, "b": 2, "c": Entity({ "d": 6, "e": 7, }, None), }, None) assert obj.dig("a") == 1 assert obj.dig("c", "d") == 6
def test_dig_for_missing_key(self): obj = Entity({ "a": 1, "b": 2, "c": Entity({ "d": 6, "e": 7, }, None), }, None) assert obj.dig("k") is None assert obj.dig("c", "k") is None
def test_iteration(self): assert set(Entity(dict(a=1, b=2, c="d"), None)) == {"a", "b", "c"}
def test_get_invalid_item(self): with pytest.raises(KeyError): Entity(dict(a=2), None)["b"]
def test_get_valid_item(self): assert Entity(dict(a=2), None)["a"] == 2
def test_get_invalid_attr(self): with pytest.raises(AttributeError): Entity(dict(a=2), None).b
def test_get_valid_attr(self): assert Entity(dict(a=2), None).a == 2
def test_items(self): obj = Entity(dict(a=1, b=2), None) assert {("a", 1), ("b", 2)} == set(obj.items())