def test_get_children(self): t = ATree(self.dbm, 'children_test') t.add_root_path(['a', 'b']) children = ['c1', 'c2', 'c3', 'c4'] children.sort() for c in children: t.add_child('b', c) id = t.save() t2 = self.dbm.get(id, ATree) self.assertEqual(t2.children_of('a'), ['b']) self.assertEqual(sorted(t2.children_of('b')), children) with self.assertRaises(ValueError): t2.children_of('not-in-tree')
def test_get_children(self): t = ATree(self.dbm, 'children_test') t.add_root_path(['a', 'b']) children = ['c1', 'c2', 'c3', 'c4'] children.sort() for c in children: t.add_child('b', c) id = t.save() t2 = self.dbm.get(id, ATree) self.assertEqual(t2.children_of('a'), ['b']) self.assertEqual(sorted(t2.children_of('b')), children) with self.assertRaises(ValueError): t2.children_of('not-in-tree')
def test_add_child(self): t = ATree(self.dbm, 'child_test') t.add_child(t.root_id, 'foo') t.add_child('foo', 'bar') t.add_child('foo', 'baz') t.add_child('bar', 'bunk') id = t.save() t2 = self.dbm.get(id, ATree) expected = [['foo'], ['foo', 'bar'], ['foo', 'baz'], ['foo', 'bar', 'bunk']] expected.sort() paths = t2.get_paths() self.assertEqual(sorted(paths), expected) with self.assertRaises(ValueError): t2.add_child('not-in-tree', 'foo')
def test_add_child(self): t = ATree(self.dbm, 'child_test') t.add_child(t.root_id, 'foo') t.add_child('foo', 'bar') t.add_child('foo', 'baz') t.add_child('bar', 'bunk') id = t.save() t2 = self.dbm.get(id, ATree) expected = [['foo'], ['foo', 'bar'], ['foo', 'baz'], ['foo', 'bar', 'bunk']] expected.sort() paths = t2.get_paths() self.assertEqual(sorted(paths), expected) with self.assertRaises(ValueError): t2.add_child('not-in-tree', 'foo')