author | Radek Brich <radek.brich@devl.cz> |
Sun, 15 Feb 2015 17:50:24 +0100 | |
changeset 116 | 165b5d65e1cb |
parent 38 | c6e170452c7f |
permissions | -rwxr-xr-x |
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
19 | 3 |
import sys |
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
4 |
sys.path.insert(0, '..') |
19 | 5 |
|
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
from tuikit.treeview import * |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
import unittest |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
19 | 9 |
|
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
class TestTreeView(unittest.TestCase): |
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
11 |
def setUp(self): |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
12 |
"""Build tree model |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
13 |
|
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
# root |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
# ├ a |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
# │ ├ c |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
# │ └ d |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
# │ ├ e |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
# │ │ └ g |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
# │ └ f |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
# │ └ h |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
# └ b |
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
23 |
|
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
24 |
""" |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
25 |
self.model = TreeModel() |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
26 |
self.model.add('/', ['a', 'b']) |
38
c6e170452c7f
Documentation, fix names of focus methods.
Radek Brich <radek.brich@devl.cz>
parents:
37
diff
changeset
|
27 |
self.model.add(['a'], [TreeNode('c'), TreeNode('d')]) |
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
28 |
self.model.add((0,1), ['e', TreeNode('f')]) |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
29 |
self.model.add([0,1,0], 'g') |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
30 |
self.model.add('/a/d/f', TreeNode('h')) |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
31 |
|
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
32 |
def test_treeiter(self): |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
33 |
"""Iterate through the tree, test result.""" |
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
res = '' |
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
35 |
for l, i, c, n in self.model: |
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
res += str(l) + str(i) + str(c) + n.name |
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
37 |
|
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
self.assertEqual(res, '112a212c222d312e411g322f411h122b') |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
|
37
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
40 |
def test_treemodel_find(self): |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
41 |
# good path |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
42 |
node = self.model.find('/a/d/f/h') |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
43 |
self.assertEqual(node.name, 'h') |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
44 |
self.assertEqual(node.path, '/a/d/f/h') |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
45 |
# bad path |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
46 |
self.assertRaises(ValueError, self.model.find, '/a/b/c') |
54dd866b8951
Clean up and update TreeView.
Radek Brich <radek.brich@devl.cz>
parents:
19
diff
changeset
|
47 |
self.assertRaises(IndexError, self.model.find, [0,1,3]) |
11
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
|
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
if __name__ == '__main__': |
762513aacc87
TreeView: Add cursor, node collapse, reworked draw.
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
unittest.main() |
19 | 51 |