started mapping tests
This commit is contained in:
38
tests/test_mapping.py
Normal file
38
tests/test_mapping.py
Normal file
@@ -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"]
|
||||
Reference in New Issue
Block a user