summaryrefslogtreecommitdiffstats
path: root/tests/test_tree.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 04:58:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 04:58:50 +0000
commit0391d056604458068132313730b9d36be055087b (patch)
tree04b24c25a8009dd1b45b83eaa8a8b86c8112163b /tests/test_tree.py
parentAdding upstream version 1.6.4. (diff)
downloadtreelib-upstream.tar.xz
treelib-upstream.zip
Adding upstream version 1.7.0.upstream/1.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_tree.py')
-rw-r--r--tests/test_tree.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_tree.py b/tests/test_tree.py
index 287b734..6fd6a64 100644
--- a/tests/test_tree.py
+++ b/tests/test_tree.py
@@ -35,6 +35,14 @@ class TreeCase(unittest.TestCase):
# |-- George
self.tree = tree
self.copytree = Tree(self.tree, deep=True)
+ self.input_dict = {
+ "Bill": "Harry",
+ "Jane": "Harry",
+ "Harry": None,
+ "Diane": "Jane",
+ "Mark": "Jane",
+ "Mary": "Harry",
+ }
@staticmethod
def get_t1():
@@ -734,3 +742,29 @@ Hárry
t.create_node(identifier="root-B")
self.assertEqual(len(t.nodes.keys()), 1)
self.assertEqual(t.root, "root-B")
+
+ def test_from_map(self):
+ tree = Tree.from_map(self.input_dict)
+ self.assertTrue(tree.size() == 6)
+ self.assertTrue(
+ tree.root == [k for k, v in self.input_dict.items() if v is None][0]
+ )
+ tree = Tree.from_map(self.input_dict, id_func=lambda x: x.upper())
+ self.assertTrue(tree.size() == 6)
+
+ def data_func(x):
+ return x.upper()
+
+ tree = Tree.from_map(self.input_dict, data_func=data_func)
+ self.assertTrue(tree.size() == 6)
+ self.assertTrue(
+ tree.get_node(tree.root).data
+ == data_func([k for k, v in self.input_dict.items() if v is None][0])
+ )
+ with self.assertRaises(ValueError):
+ # invalid input payload without a root
+ tree = Tree.from_map({"a": "b"})
+
+ with self.assertRaises(ValueError):
+ # invalid input payload without more than 1 root
+ tree = Tree.from_map({"a": None, "b": None})