def test_get_paths(self): t = ATree(self.dbm, 'paths_test') t.add_path([ATree.root_id, '1', '2', '3']) t.add_path(['1', '1.1']) expected = [['1'], ['1', '2'], ['1', '2', '3'], ['1', '1.1']] tree_paths = t.get_paths() for p in expected: self.assertIn(p, tree_paths)
def test_get_leaf_paths(self): t = ATree(self.dbm, 'leaf_paths_test') paths = [(ATree.root_id, 'a', 'b', 'c', 'd'), (ATree.root_id, '1', '2', '3', '4')] for p in paths: t.add_path(p) tree_paths = t.get_leaf_paths() for p in [list(p[1:]) for p in paths]: self.assertIn(p, tree_paths)
def test_add_path(self): t1 = ATree(self.dbm, 'test_add_path_1') t1.graph.add_path([ATree.root_id, '1', '2', '3', '4', '5']) t1_id = t1.save() t2 = ATree(self.dbm, 'test_add_path_2') t2.add_path([ATree.root_id, '1', '2', '3', '4', '5']) t2_id = t2.save() self.assertDictEqual(self.dbm.get(t1_id, ATree).graph.adj, self.dbm.get(t2_id, ATree).graph.adj)
def test_get_paths(self): t = ATree(self.dbm, 'paths_test') t.add_path([ATree.root_id, '1', '2', '3']) t.add_path(['1', '1.1']) expected = [['1'], ['1', '2'], ['1', '2', '3'], ['1', '1.1']] tree_paths = t.get_paths() for p in expected: self.assertIn(p, tree_paths)
def test_add_path(self): t1 = ATree(self.dbm, 'test_add_path_1') t1.graph.add_path([ATree.root_id, '1', '2', '3', '4', '5']) t1_id = t1.save() t2 = ATree(self.dbm, 'test_add_path_2') t2.add_path([ATree.root_id, '1', '2', '3', '4', '5']) t2_id = t2.save() self.assertDictEqual(self.dbm.get(t1_id, ATree).graph.adj, self.dbm.get(t2_id, ATree).graph.adj)
def test_get_leaf_paths(self): t = ATree(self.dbm, 'leaf_paths_test') paths = [(ATree.root_id, 'a', 'b', 'c', 'd'), (ATree.root_id, '1', '2', '3', '4')] for p in paths: t.add_path(p) tree_paths = t.get_leaf_paths() for p in [list(p[1:]) for p in paths]: self.assertIn(p, tree_paths)
def test_add_path_bad_args(self): # blank path with self.assertRaises(AssertionError): t = ATree(self.dbm, '_test_tree') t.add_path(None) # path is not a sequence with self.assertRaises(AssertionError): t = ATree(self.dbm, '_test_tree') t.add_path('foo') # path is not a sequence with self.assertRaises(AssertionError): t = ATree(self.dbm, '_test_tree') t.add_path(1) # first path item not in graph with self.assertRaises(ValueError): t = ATree(self.dbm, '_test_tree') t.add_path(['1', '2', '3', '4'])
def test_add_path_bad_args(self): # blank path with self.assertRaises(AssertionError): t = ATree(self.dbm, '_test_tree') t.add_path(None) # path is not a sequence with self.assertRaises(AssertionError): t = ATree(self.dbm, '_test_tree') t.add_path('foo') # path is not a sequence with self.assertRaises(AssertionError): t = ATree(self.dbm, '_test_tree') t.add_path(1) # first path item not in graph with self.assertRaises(ValueError): t = ATree(self.dbm, '_test_tree') t.add_path(['1', '2', '3', '4'])