def test_lists(self): kobj = KadetTestObj(name="testObj", size=5) kobj.root.with_lists = [ Dict({"i_am_inside_a_list": True}), BaseObj.from_dict({"me": "too"}), BaseObj.from_dict({ "list_of_objs": [BaseObj.from_dict(dict(a=1, b=2)), Dict(dict(c=3, d=4))] }), ] output = kobj.to_dict() desired_output = { "name": "testObj", "size": 5, "first_key": 1, "traditional_key": 3, "nested": { "first_key": 2 }, "with_dict": { "A": "dict" }, "with_baseobj_init_as": { "init": "as" }, "with_baseobj": { "inside": "BaseObj" }, "with_another_dict": { "Another": "Dict" }, "with_lists": [ { "i_am_inside_a_list": True }, { "me": "too" }, { "list_of_objs": [{ "a": 1, "b": 2 }, { "c": 3, "d": 4 }] }, ], } self.assertEqual(output, desired_output)
def body(self): self.root.name = self.kwargs.name self.root.size = self.kwargs.size self.root.first_key = 1 self.root.nested.first_key = 2 self.root['traditional_key'] = 3 self.root.with_dict = {'A': 'dict'} self.root.with_baseobj_init_as = BaseObj.from_dict({'init': 'as'}) bobj = BaseObj() bobj.root.inside = "BaseObj" self.root.with_baseobj = bobj self.root.with_another_dict = Dict({'Another': 'Dict'})
def body(self): self.root.name = self.kwargs.name self.root.size = self.kwargs.size self.root.first_key = 1 self.root.nested.first_key = 2 self.root["traditional_key"] = 3 self.root.with_dict = {"A": "dict"} self.root.with_baseobj_init_as = BaseObj.from_dict({"init": "as"}) bobj = BaseObj() bobj.root.inside = "BaseObj" self.root.with_baseobj = bobj self.root.with_another_dict = Dict({"Another": "Dict"})
def test_parse_kwargs(self): kobj = BaseObj.from_dict({"this": "that", "not_hidden": True}) output = kobj.to_dict() desired_output = {"this": "that", "not_hidden": True} self.assertEqual(output, desired_output)