tests/test_treeview.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 21:56:20 +0200
changeset 113 6796adfdc7eb
parent 38 c6e170452c7f
permissions -rwxr-xr-x
Merge. Due to my schizophrenia, I've accidentally forked my own code. The other set of changes were found in another computer.

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