tests/test_treeview.py
author Radek Brich <radek.brich@devl.cz>
Sat, 29 Dec 2012 12:16:06 +0100
changeset 41 37b7dfc3eae6
parent 38 c6e170452c7f
permissions -rwxr-xr-x
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.

#!/usr/bin/env python3

import sys
sys.path.insert(0, '..')

from tuikit.treeview import *
import unittest


class TestTreeView(unittest.TestCase):
    def setUp(self):
        """Build tree model

        # root
        # ├ a
        # │ ├ c
        # │ └ d
        # │   ├ e
        # │   │ └ g
        # │   └ f
        # │     └ h
        # └ b

        """
        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 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()