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

Class TestBoxPaths

test/test_coverage_paths.py:25–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25class TestBoxPaths:
26 def test_ipython_probes_are_not_defaulted(self, fake_ipython):
27 b = Box(default_box=True)
28 assert b.getdoc is None
29 assert b.shape is None
30 assert b.other == Box()
31
32 def test_ipython_installed_but_not_running(self, fake_ipython, monkeypatch):
33 monkeypatch.setattr(fake_ipython, "get_ipython", lambda: None)
34 assert Box(default_box=True).shape == Box()
35
36 def test_parse_box_dots_without_separator(self):
37 with pytest.raises(BoxError):
38 _parse_box_dots(Box(), "nodots")
39
40 def test_tuple_holding_box_list_to_dict(self):
41 b = Box({"a": (BoxList([1, {"x": 1}]), Box(y=2))})
42 assert b.to_dict() == {"a": ([1, {"x": 1}], {"y": 2})}
43 assert type(b.to_dict()["a"][0]) is list
44 assert type(b.to_dict()["a"][0][1]) is dict
45
46 def test_default_box_attr_function_arguments(self):
47 def positional(key, box_instance):
48 return f"{key}-{type(box_instance).__name__}"
49
50 def keyword(*, key, box_instance):
51 return f"{key}:{type(box_instance).__name__}"
52
53 assert Box(default_box=True, default_box_attr=positional).hi == "hi-Box"
54 assert Box(default_box=True, default_box_attr=keyword).hi == "hi:Box"
55
56 def bad(name):
57 return name
58
59 with pytest.raises(BoxError, match="only have the required arguments .key. and .box_instance., not .name."):
60 Box(default_box=True, default_box_attr=bad).hi
61
62 def test_create_on_get_dotted_through_non_container(self):
63 b = Box({"a": 5}, default_box=True, box_dots=True, default_box_create_on_get=True)
64 assert b["a.b"] == Box()
65 assert b.to_dict() == {"a": 5}
66
67 def test_unhashable_key(self):
68 with pytest.raises(BoxTypeError):
69 Box()[["unhashable"]]
70
71 def test_ephemeral_child_of_frozen_box(self):
72 b = Box(default_box=True, frozen_box=True)
73 child = b.missing
74 with pytest.raises(BoxError, match="frozen"):
75 child.x = 1
76 assert b.to_dict() == {}
77
78 def test_ephemeral_child_without_conversion_box(self):
79 b = Box(default_box=True, conversion_box=False)
80 b.new.key = 1
81 assert b.to_dict() == {"new": {"key": 1}}
82

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected