def test_add_path_with_data(self):
        t = ATree(self.dbm, 'data_paths_test')
        path = [('a', {'a': 1}), ('b', {'b': 2}), ('c', {'c': 3, 'c1': 4})]
        t.add_root_path(path)
        id = t.save()
        t2 = self.dbm.get(id, ATree)

        for node, data in path:
            self.assertDictEqual(t2.get_data_for(node), data)
    def test_get_node_data(self):
        t1 = ATree(self.dbm, 'data_test_tree')
        t1.add_root_path(['1', '2', '3'])
        ddict = {'1': 1, '2': 2}
        t1.set_data_for('1', ddict)
        id = t1.save()

        t2 = self.dbm.get(id, ATree)
        self.assertDictEqual(ddict, t2.get_data_for('1'))
    def test_add_path_with_data(self):
        t = ATree(self.dbm, 'data_paths_test')
        path = [('a', {'a': 1}), ('b', {'b': 2}), ('c', {'c': 3, 'c1': 4})]
        t.add_root_path(path)
        id = t.save()
        t2 = self.dbm.get(id, ATree)

        for node, data in path:
            self.assertDictEqual(t2.get_data_for(node), data)
    def test_get_node_data(self):
        t1 = ATree(self.dbm, 'data_test_tree')
        t1.add_root_path(['1', '2', '3'])
        ddict = {'1': 1, '2': 2}
        t1.set_data_for('1', ddict)
        id = t1.save()

        t2 = self.dbm.get(id, ATree)
        self.assertDictEqual(ddict, t2.get_data_for('1'))
 def test_ancestors_of(self):
     t = ATree(self.dbm, 'children_test')
     t.add_root_path(['a', 'b', 'c'])
     id = t.save()
     t2 = self.dbm.get(id, ATree)
     self.assertEqual(t2.ancestors_of('a'), [])
     self.assertEqual(t2.ancestors_of('b'), ['a'])
     self.assertEqual(t2.ancestors_of('c'), ['a', 'b'])
     with self.assertRaises(ValueError):
         t2.ancestors_of('not-in-tree')
 def test_parent_of(self):
     t = ATree(self.dbm, 'children_test')
     t.add_root_path(['a', 'b', 'c'])
     id = t.save()
     t2 = self.dbm.get(id, ATree)
     self.assertIsNone(t2.parent_of(t2.root_id))
     self.assertEqual(t2.parent_of('a'), t2.root_id)
     self.assertEqual(t2.parent_of('c'), 'b')
     with self.assertRaises(ValueError):
         t2.parent_of('not-in-tree')
 def test_ancestors_of(self):
     t = ATree(self.dbm, 'children_test')
     t.add_root_path(['a', 'b', 'c'])
     id = t.save()
     t2 = self.dbm.get(id, ATree)
     self.assertEqual(t2.ancestors_of('a'), [])
     self.assertEqual(t2.ancestors_of('b'), ['a'])
     self.assertEqual(t2.ancestors_of('c'), ['a', 'b'])
     with self.assertRaises(ValueError):
         t2.ancestors_of('not-in-tree')
 def test_parent_of(self):
     t = ATree(self.dbm, 'children_test')
     t.add_root_path(['a', 'b', 'c'])
     id = t.save()
     t2 = self.dbm.get(id, ATree)
     self.assertIsNone(t2.parent_of(t2.root_id))
     self.assertEqual(t2.parent_of('a'), t2.root_id)
     self.assertEqual(t2.parent_of('c'), 'b')
     with self.assertRaises(ValueError):
         t2.parent_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')
Exemplo n.º 10
0
 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')
Exemplo n.º 11
0
    def non_string_node_should_raise_valueerror(self):
        t = ATree(self.dbm, 'test_tree')
        with self.assertRaises(ValueError):
            t.add_root_path([1])

        with self.assertRaises(ValueError):
            t.add_root_path([{1: 1}])

        with self.assertRaises(ValueError):
            t.add_root_path([None])

        with self.assertRaises(ValueError):
            t.add_root_path(['a', 1, 'c'])
Exemplo n.º 12
0
    def non_string_node_should_raise_valueerror(self):
        t = ATree(self.dbm, 'test_tree')
        with self.assertRaises(ValueError):
            t.add_root_path([1])

        with self.assertRaises(ValueError):
            t.add_root_path([{1: 1}])

        with self.assertRaises(ValueError):
            t.add_root_path([None])

        with self.assertRaises(ValueError):
            t.add_root_path(['a', 1, 'c'])