예제 #1
0
    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
예제 #2
0
    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
예제 #3
0
 def test_iteration(self):
     assert set(Entity(dict(a=1, b=2, c="d"), None)) == {"a", "b", "c"}
예제 #4
0
 def test_get_invalid_item(self):
     with pytest.raises(KeyError):
         Entity(dict(a=2), None)["b"]
예제 #5
0
 def test_get_valid_item(self):
     assert Entity(dict(a=2), None)["a"] == 2
예제 #6
0
 def test_get_invalid_attr(self):
     with pytest.raises(AttributeError):
         Entity(dict(a=2), None).b
예제 #7
0
 def test_get_valid_attr(self):
     assert Entity(dict(a=2), None).a == 2
예제 #8
0
    def test_items(self):
        obj = Entity(dict(a=1, b=2), None)

        assert {("a", 1), ("b", 2)} == set(obj.items())