def test_unindent_simple(self): root = NestedList(["root"]) child = root.insert_child(["child"]) child.unindent(root) target = NestedList(["root"]) target.insert_sibling(["child"]) self.assertEqual(root, target)
def test_iter(self): root = NestedList() # breakpoint() self.__test_iter_helper(root, [root]) child = root.insert_child() self.__test_iter_helper(root, [root, child]) child2 = child.insert_sibling() self.__test_iter_helper(root, [root, child, child2]) grandchild = child2.insert_child() self.__test_iter_helper(root, [root, child, child2, grandchild]) child3 = child2.insert_sibling() self.__test_iter_helper(root, [root, child, child2, grandchild, child3]) greatgrandchild = grandchild.insert_child() self.__test_iter_helper( root, [root, child, child2, grandchild, greatgrandchild, child3]) greatgreatgrandchild = greatgrandchild.insert_child() self.__test_iter_helper(root, [ root, child, child2, grandchild, greatgrandchild, greatgreatgrandchild, child3 ]) sibling2 = root.insert_sibling() sibling = root.insert_sibling() self.__test_iter_helper(root, [ root, child, child2, grandchild, greatgrandchild, greatgreatgrandchild, child3, sibling, sibling2 ])
def test_str(self): root = NestedList(["123", "1"]) target = "123 1\n" self.assertEqual(str(root), target) root.insert_child(["1234"]) target += " 1234\n" self.assertEqual(str(root), target) root.insert_sibling(["12"]) target += "12\n"
def test_columns(self): root = NestedList(["123", "1"]) target = "123 1\n" self.__comp_str_to_node(root, target) root.insert_sibling(["1234"]) target = "123 1\n" target += "1234\n" self.__comp_str_to_node(root, target) del root.sibling target = "123 1\n" self.__comp_str_to_node(root, target)
def test_instantiation(self): root = NestedList() self.assertTrue(isinstance(root, NestedList)) child = root.insert_child() self.assertTrue(isinstance(child, NestedList)) sibling = root.insert_sibling() self.assertTrue(isinstance(sibling, NestedList))
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_get_count(self): root = NestedList() self.assertEqual(root.count(), 1) sibling = root.insert_sibling() self.assertEqual(root.count(), 2) child = sibling.insert_child() self.assertEqual(sibling.count(), 2) self.assertEqual(root.count(), 3) grandchild = child.insert_child() self.assertEqual(root.count(), 4) grandchild2 = grandchild.insert_sibling() self.assertEqual(root.count(), 5) grandchild.insert_sibling() self.assertEqual(root.count(), 6) child.insert_sibling() self.assertEqual(root.count(), 7)
def test_delete_simple(self): root = NestedList(["root"]) root.insert_sibling(["sib"]) del root.sibling target = NestedList(["root"]) self.assertEqual(root, target) root.insert_child(["child"]) del root.child self.assertEqual(root, target) root.insert_sibling(["sib1"]) root.insert_sibling(["sib2"]) del root.sibling target.insert_sibling(["sib1"]) self.assertEqual(root, target)
def test_delete_sibling(self): one = NestedList(["one"]) two = one.insert_sibling(["two"]) three = two.insert_child(["three"]) four = three.insert_sibling(["four"]) five = two.insert_sibling(["five"]) target = "one\n" \ + "two\n" \ + " three\n" \ + " four\n" \ + "five\n" actual = str(one) self.assertEqual(target, actual) del one.sibling target = "one\n" \ + " three\n" \ + " four\n" \ + "five\n" actual = str(one) self.assertEqual(target, actual)