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

Class TestSubclassing

test/test_edge_cases.py:902–945  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

900
901
902class TestSubclassing:
903 def test_box_defaults_inherit_and_explicit_options_win(self):
904 child = ChildDefaults({"a": {"b": 1}})
905 assert child._box_config["box_dots"] is True
906 assert child._box_config["default_box"] is True
907 assert child["a.b"] == 1
908 assert ParentDefaults()._box_config["default_box"] is False
909 assert ChildDefaults(box_dots=False)._box_config["box_dots"] is False
910 assert ChildDefaults(default_box=False)._box_config["default_box"] is False
911 assert Box()._box_config["box_dots"] is False
912 assert DDBox(default_box=False)._box_config["default_box"] is False
913
914 def test_unknown_box_default_is_rejected_at_class_creation(self):
915 with pytest.raises(BoxError, match="not_an_option"):
916
917 class Bad(Box):
918 _box_defaults = {"not_an_option": 1}
919
920 def test_subclass_defaults_apply_to_nested_conversion_from_json_and_yaml(self):
921 text = '{"a": {"b": [{"c": 1}]}}'
922 for bx in (ChildDefaults.from_json(text), ChildDefaults.from_yaml(text)):
923 assert type(bx) is ChildDefaults
924 assert type(bx.a) is ChildDefaults
925 assert type(bx.a.b[0]) is ChildDefaults
926 assert bx["a.b[0].c"] == 1
927 assert bx.a.nothing == {} and "nothing" not in bx.a
928 explicit = ChildDefaults.from_json(text, box_dots=False)
929 assert explicit.a._box_config["box_dots"] is False
930
931 def test_property_setter_and_deleter_are_used_not_the_data(self):
932 bx = PropBox({"k": 1})
933 bx.temp = 5
934 assert bx.temp == 5
935 assert "temp" not in bx
936 assert bx.to_dict() == {"k": 1}
937 del bx.temp
938 assert bx.temp is None
939 bx["temp"] = "as key"
940 assert bx["temp"] == "as key"
941 assert bx.temp is None
942 assert bx.describe() == "described"
943 bx["describe"] = 1
944 assert bx.describe() == "described"
945 assert bx["describe"] == 1
946
947
948class TestDictCompat:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected