tests/test_treeview.py
author Radek Brich <radek.brich@devl.cz>
Fri, 18 Jan 2013 22:36:50 +0100
changeset 62 2f61931520c9
parent 38 c6e170452c7f
permissions -rwxr-xr-x
Rework layouts: Layout is now normal Container which places its children upon resize event. Drop TopWindow, top is now any subclass of Container. Add floater concept: floaters are widgets drawn over normal widgets, not clipped by parent. Add HScrollbar and Scrollbar abstract base class.

#!/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()