File: TreeListCtrlTest.py

package info (click to toggle)
taskcoach 1.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 32,496 kB
  • ctags: 17,810
  • sloc: python: 72,170; makefile: 254; ansic: 120; xml: 29; sh: 16
file content (90 lines) | stat: -rwxr-xr-x 3,375 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'''
Task Coach - Your friendly task manager
Copyright (C) 2004-2014 Task Coach developers <developers@taskcoach.org>

Task Coach is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Task Coach is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

import wx
import TreeCtrlTest
from unittests import dummy
from taskcoachlib import widgets


class TreeListCtrlTestCase(TreeCtrlTest.TreeCtrlTestCase):

    onSelect = getItemTooltipText = None

    def setUp(self):
        super(TreeListCtrlTestCase, self).setUp()
        self._columns = self.createColumns()
        self.treeCtrl = widgets.TreeListCtrl(self.frame, self.columns(), 
            self.getItemTooltipText,
            self.onSelect, dummy.DummyUICommand(), dummy.DummyUICommand())
        imageList = wx.ImageList(16, 16)
        for bitmapName in ['led_blue_icon', 'folder_blue_icon']:
            imageList.Add(wx.ArtProvider_GetBitmap(bitmapName, wx.ART_MENU, 
                          (16,16)))
        self.treeCtrl.AssignImageList(imageList) # pylint: disable=E1101

    def createColumns(self):
        names = ['treeColumn'] + ['column%d'%index for index in range(1, 5)]
        return [widgets.Column(name, name, ('view', 'whatever'), None) for name in names]
        
    def columns(self):
        return self._columns

    
class TreeListCtrlTest(TreeListCtrlTestCase, TreeCtrlTest.CommonTestsMixin):
    pass


class TreeListCtrlColumnsTest(TreeListCtrlTestCase):
    def setUp(self):
        super(TreeListCtrlColumnsTest, self).setUp()
        self.children[None] = [TreeCtrlTest.DummyDomainObject('item')]
        self.treeCtrl.RefreshAllItems(1)
        self.visibleColumns = self.columns()[1:]
        
    def assertColumns(self):
        # pylint: disable=E1101
        self.assertEqual(len(self.visibleColumns)+1, self.treeCtrl.GetColumnCount())
        item = self.treeCtrl.GetFirstChild(self.treeCtrl.GetRootItem())[0]
        for columnIndex in range(1, len(self.visibleColumns)):
            self.assertEqual('item', self.treeCtrl.GetItemText(item, columnIndex))
    
    def showColumn(self, name, show=True):
        column = widgets.Column(name, name, ('view', 'whatever'), None)
        self.treeCtrl.showColumn(column, show)
        if show:
            index = self.columns()[1:].index(column)
            self.visibleColumns.insert(index, column)
        else:
            self.visibleColumns.remove(column)
    
    def testAllColumnsVisible(self):
        self.assertColumns()
        
    def testHideColumn(self):
        self.showColumn('column1', False)
        self.assertColumns()
        
    def testHideLastColumn(self):
        lastColumnHeader = 'column%d'%len(self.visibleColumns)
        self.showColumn(lastColumnHeader, False)
        self.assertColumns()
        
    def testShowColumn(self):
        self.showColumn('column2', False)
        self.showColumn('column2', True)