tests/test_treeview.py
changeset 37 54dd866b8951
parent 19 5e78d52ebb24
child 38 c6e170452c7f
--- a/tests/test_treeview.py	Mon Dec 17 00:24:34 2012 +0100
+++ b/tests/test_treeview.py	Mon Dec 17 21:07:59 2012 +0100
@@ -1,16 +1,16 @@
 #!/usr/bin/env python3
 
 import sys
-sys.path.append('..')
+sys.path.insert(0, '..')
 
 from tuikit.treeview import *
 import unittest
 
 
 class TestTreeView(unittest.TestCase):
-    def test_treemodel(self):
-        '''Build tree model, iterate through the tree, test result.'''
-        # build tree model
+    def setUp(self):
+        """Build tree model
+
         # root
         # ├ a
         # │ ├ c
@@ -20,19 +20,31 @@
         # │   └ f
         # │     └ h
         # └ b
-        model = TreeModel()
-        model.add('/',  ['a', 'b'])
-        model.add('/a', ['c', 'd'])
-        model.add((0,1), ['e', 'f'])
-        model.add('/0/1/0', 'g')
-        model.add('/a/d/f', 'h')
-        
+
+        """
+        self.model = TreeModel()
+        self.model.add('/',  ['a', 'b'])
+        self.model.add('/a', [TreeNode('c'), TreeNode('d')])
+        self.model.add((0,1), ['e', TreeNode('f')])
+        self.model.add([0,1,0], 'g')
+        self.model.add('/a/d/f', TreeNode('h'))
+
+    def test_treeiter(self):
+        """Iterate through the tree, test result."""
         res = ''
-        for l, i, c, n in model:
+        for l, i, c, n in self.model:
             res += str(l) + str(i) + str(c) + n.name
-            
+
         self.assertEqual(res, '112a212c222d312e411g322f411h122b')
 
+    def test_treemodel_find(self):
+        # good path
+        node = self.model.find('/a/d/f/h')
+        self.assertEqual(node.name, 'h')
+        self.assertEqual(node.path, '/a/d/f/h')
+        # bad path
+        self.assertRaises(ValueError, self.model.find, '/a/b/c')
+        self.assertRaises(IndexError, self.model.find, [0,1,3])
 
 if __name__ == '__main__':
     unittest.main()