MCPcopy Create free account
hub / github.com/cdgriffith/Box / TestEphemeralDefaultBox

Class TestEphemeralDefaultBox

test/test_edge_cases.py:182–252  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

180
181
182class TestEphemeralDefaultBox:
183 def test_chained_assignment_creates_every_parent(self):
184 bx = Box(default_box=True)
185 bx.a.b.c = 1
186 bx.a.b.d.e = 2
187 bx["x"].y["z"] = 3
188 assert bx == {"a": {"b": {"c": 1, "d": {"e": 2}}}, "x": {"y": {"z": 3}}}
189
190 def test_lookups_never_store_and_look_empty(self):
191 bx = Box({"real": 1}, default_box=True)
192 ghost = bx.a.b.c
193 assert not ghost
194 assert len(ghost) == 0
195 assert "x" not in ghost
196 assert ghost == {}
197 assert ghost == Box()
198 assert bx["q"] == {}
199 assert bx.get("w") == {}
200 assert bx == {"real": 1}
201 assert "a" not in bx
202
203 def test_stale_child_does_not_overwrite_real_value(self):
204 bx = Box(default_box=True)
205 stale = bx.a
206 bx.a = {"k": 1}
207 stale.z = 2
208 assert bx.a == {"k": 1}
209 assert stale == {"z": 2}
210
211 def test_child_stored_elsewhere_is_copied_not_aliased(self):
212 bx = Box(default_box=True)
213 child = bx.a
214 bx.other = child
215 child.x = 1
216 assert bx.other == {}
217 assert bx.a == {"x": 1}
218
219 def test_box_dots_missing_list_and_dict_paths_are_created_on_write(self):
220 bx = DDBox()
221 assert bx["rows[3].name"] == {}
222 assert bx == {}
223 bx["rows[1].name"] = "x"
224 bx["a.b.c"] = 1
225 assert bx.rows == [None, {"name": "x"}]
226 assert bx["a.b.c"] == 1
227 assert isinstance(bx.rows, BoxList)
228
229 def test_frozen_default_box_refuses_child_writes(self):
230 bx = Box({"a": 1}, default_box=True, frozen_box=True)
231 with pytest.raises(BoxError):
232 bx.missing.x = 1
233 with pytest.raises(BoxError):
234 bx["m"].n = 1
235 assert bx == {"a": 1}
236
237 def test_update_and_merge_update_on_ephemeral_child_attach_it(self):
238 bx = Box(default_box=True)
239 bx.a.merge_update({"x": {"y": 1}})

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected