def test_serialization_complex(self): root = NestedList(["one", "two", "three"]) child = root.insert_child(["child1", "child2"]) grandchild = child.insert_child(["gc1"]) grandchild.insert_sibling(["gc2", "gc2"]) sibling = root.insert_sibling() sibling.insert_sibling(["sib2", "sib2"]) pickle = root.serialize() copy = NestedList.deserialize(pickle) self.assertEqual(str(root), str(copy)) self.assertEqual(root, copy)
def test_serialization_simple(self): one = NestedList(["one", "two", "three"]) pickle = one.serialize() copy = NestedList.deserialize(pickle) self.assertEqual(str(one), str(copy)) self.assertEqual(one, copy)
def load(self, file_path: str) -> NestedList: assert file_path.endswith(self.__file_extension) with open(file_path, 'r') as file: pickle = json.load(file) return NestedList.deserialize(pickle)