author | Radek Brich <radek.brich@devl.cz> |
Wed, 20 Aug 2014 14:24:48 +0200 | |
changeset 99 | f3063f08ba81 |
permissions | -rwxr-xr-x |
99
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python3 |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
2 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
3 |
import sys |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
4 |
sys.path.insert(0, '..') |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
5 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
6 |
from tuikit.tableview import * |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
7 |
import unittest |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
8 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
9 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
10 |
class TestTableView(unittest.TestCase): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
11 |
def setUp(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
12 |
self.abs_model = AbstractTableModel() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
13 |
self.model = TableModel() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
14 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
15 |
def test_initial(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
16 |
self._test_empty_model(self.abs_model) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
17 |
self._test_empty_model(self.model) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
18 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
19 |
def test_one(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
20 |
self._insert_data() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
21 |
self._fill_data() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
22 |
self._insert_headers() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
23 |
self._test_empty_headers() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
24 |
self._fill_headers() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
25 |
self._remove_data() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
26 |
self._clear_data() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
27 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
28 |
def test_two(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
29 |
self._insert_headers() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
30 |
self._insert_data() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
31 |
self._test_empty_headers() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
32 |
self._fill_headers() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
33 |
self._fill_data() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
34 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
35 |
def _test_empty_model(self, model): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
36 |
self.assertEqual(model.row_count(), 0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
37 |
self.assertEqual(model.column_count(), 0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
38 |
self.assertRaises(IndexError, model.get_row, 0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
39 |
self.assertRaises(IndexError, model.get_column, 0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
40 |
self.assertRaises(IndexError, model.get_item, 0, 0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
41 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
42 |
def _insert_data(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
43 |
for _i in range(3): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
44 |
self.model.insert_row(0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
45 |
self.model.insert_column(0) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
46 |
self.assertEqual(self.model.row_count(), 3) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
47 |
self.assertEqual(self.model.column_count(), 3) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
48 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
49 |
def _fill_data(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
50 |
for row in range(3): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
51 |
for col in range(3): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
52 |
self.model.set_item(row, col, row*3 + col+1) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
53 |
self.assertEqual(self.model.get_row(0), [1,2,3]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
54 |
self.assertEqual(self.model.get_row(1), [4,5,6]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
55 |
self.assertEqual(self.model.get_row(2), [7,8,9]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
56 |
self.assertEqual(self.model.get_column(0), [1,4,7]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
57 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
58 |
def _insert_headers(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
59 |
self.model.set_num_headers(2, 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
60 |
self.assertEqual(self.model.row_header_count(), 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
61 |
self.assertEqual(self.model.column_header_count(), 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
62 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
63 |
def _test_empty_headers(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
64 |
self.assertEqual(self.model.get_row_header(0, 0), None) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
65 |
self.assertEqual(self.model.get_row_header(2, 1), None) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
66 |
self.assertEqual(self.model.get_column_header(0, 0), None) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
67 |
self.assertEqual(self.model.get_column_header(2, 1), None) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
68 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
69 |
def _fill_headers(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
70 |
for i in range(3): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
71 |
for header in range(2): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
72 |
self.model.set_column_header(i, header, header*3 + i + 1) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
73 |
self.model.set_row_header(i, header, header*3 + i + 1) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
74 |
self.assertEqual(self.model.get_column_header(1, 0), 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
75 |
self.assertEqual(self.model.get_column_header(1, 1), 5) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
76 |
self.assertEqual(self.model.get_row_header(1, 0), 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
77 |
self.assertEqual(self.model.get_row_header(1, 1), 5) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
78 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
79 |
def _remove_data(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
80 |
self.model.remove_row(1) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
81 |
self.assertEqual(self.model.get_row(0), [1,2,3]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
82 |
self.assertEqual(self.model.get_row(1), [7,8,9]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
83 |
self.assertEqual(self.model.get_column(0), [1,7]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
84 |
self.model.remove_column(1) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
85 |
self.assertEqual(self.model.get_row(0), [1,3]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
86 |
self.assertEqual(self.model.get_row(1), [7,9]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
87 |
self.assertEqual(self.model.get_column(1), [3,9]) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
88 |
self.assertRaises(IndexError, self.model.get_row, 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
89 |
self.assertRaises(IndexError, self.model.get_column, 2) |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
90 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
91 |
def _clear_data(self): |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
92 |
self.model.clear() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
93 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
94 |
|
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
95 |
if __name__ == '__main__': |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
96 |
unittest.main() |
f3063f08ba81
Update TableView (old uncommitted work).
Radek Brich <radek.brich@devl.cz>
parents:
diff
changeset
|
97 |