diff --git a/tests/test_mapping.py b/tests/test_mapping.py new file mode 100644 index 0000000..e05b798 --- /dev/null +++ b/tests/test_mapping.py @@ -0,0 +1,38 @@ +from hooked_containers.mapping import HookedMapping + + +class TestHookedMapping: + class TestConstruction: + def test_empty(self): + m = HookedMapping({}) + assert m._data == {} + assert dict(m) == {} + + def test_with_existing(self): + existing = {"a": 1, "b": 2} + og_id = id(existing) + m = HookedMapping(existing) + assert id(m._data) == og_id + assert dict(m) == existing + + def test_nesting(self): + existing = {"a": {"x": 1}, "b": {"y": 2}} + m = HookedMapping(existing) + assert dict(m) == existing + assert dict(m["a"]) == {"x": 1} + assert dict(m["b"]) == {"y": 2} + + class TestMappingOps: + def test_setitem(self): + m = HookedMapping({}) + m["a"] = 1 + assert m._data == {"a": 1} + + def test_getitem(self): + m = HookedMapping({"a": 1}) + assert m["a"] == 1 + + def test_delitem(self): + m = HookedMapping({"a": 1}) + del m["a"] + assert not m["a"]