Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/test_history.py
blob: 699d02e03b512e25b189e747b8a7acb8f915a272 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# coding: UTF-8
# Copyright 2009, 2010 Thomas Jourdan
#
# This program 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.
#
# This program 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import unittest

import model_history
import cairo

class TestKandidHistory(unittest.TestCase):

    def setUp(self):
        self.id_count = 0

    def tearDown(self):
        pass

    def test_history(self):
        history = model_history.KandidHistory.instance()
        history.clear()
        self.assertFalse(history.contains('_missing'))
        self.assertEqual(None, history.get_surface('_missing'))

        history.rember_parents('_ab', '_a', '_b')
        self.assertTrue(history.contains('_ab'))
#        self.assertTrue(history.contains('_a'))
#        self.assertTrue(history.contains('_c'))
        p_ab = history.get_parents('_ab')
        self.assertEqual('_a', p_ab[0],)
        self.assertEqual('_b', p_ab[1])
        
        history.rember_parents('_abc', '_ab', '_c')
        self.assertEqual('_c', history.get_parents('_abc')[1])
        self.assertEqual('_a', history.get_parents(
                                          history.get_parents('_abc')[0])[0])
        
        s_abc = cairo.ImageSurface(cairo.FORMAT_ARGB32, 2, 2)
        history.link_surface('_abc', s_abc)
        self.assertEqual(id(s_abc), id(history.get_surface('_abc')))
        
        history.rember_parents('_abcd', '_abc', '_d')
        self.assertEqual('_d', history.get_parents('_abcd')[1])
        self.assertEqual('_a', history.get_parents(history.get_parents(
                                          history.get_parents('_abcd')[0])[0])[0])
        
        history.unlink('_abc')
        self.assertTrue(history.contains('_abc'))
        history.unlink('_abcd')
        print history.parents
        self.assertFalse(history.contains('_abcd'))
        self.assertFalse(history.contains('_abc'))

    def test_history_overflow(self):
        history = model_history.KandidHistory.instance()
        history.clear()
        self._add(7, history)
        for my_id, parent in history.parents.iteritems():
            print my_id, parent

    def _add(self, depth, history):
        self.id_count += 1
        my_id = '_' + str(self.id_count)
        if depth > 0:
            p0_id = self._add(depth-2, history)
            p1_id = self._add(depth-1, history)
            history.rember_parents(my_id, p0_id, p1_id)
        history.link_surface(my_id, object())
        return my_id

#    def test_treestore(self):
#        history = ka_history.KandidHistory.instance()
#        history.clear()
#        history.rember_parents('_ab', '_a', '_b')
#        history.rember_parents('_abc', '_ab', '_c')
#        history.rember_parents('_abcd', '_abc', '_d')
#        treestore = history.get_treestore('_abcd')
#        PyApp(treestore, '_abcd')
#        gtk.main()

#class PyApp(gtk.Window):
#    def __init__(self, treestore, my_id):
#        super(PyApp, self).__init__()
#        self.set_size_request(400, 400)
#        self.set_position(gtk.WIN_POS_CENTER)
#        self.connect('destroy', gtk.main_quit)
#        self.set_title('History Tree')
#        treeview = gtk.TreeView()
#        treeview.set_direction(gtk.TEXT_DIR_RTL)
#        treeview.set_property('enable-tree-lines', True)
#        treeview.set_property('level-indentation', 50)
#
#        ancestors = gtk.TreeViewColumn()
#        ancestors.set_title('Ancestors for ' + my_id)
#        text_cell = gtk.CellRendererText()
#        img_cell = gtk.CellRendererPixbuf()
#        ancestors.pack_start(img_cell, False)
#        ancestors.pack_start(text_cell,True)
#        ancestors.add_attribute(img_cell, 'pixbuf', 0)
#        ancestors.add_attribute(text_cell, 'text', 1)
#        treeview.append_column(ancestors)
#
#        treeview.set_model(treestore)
#        treeview.expand_all()
#
#        self.add(treeview)
#        self.show_all()

#ka_debug.info('starting TestKandidHistory')
#ka_debug.err('testing error message channel.')
#alltests = unittest.TestSuite((\
#                 unittest.makeSuite(TestKandidHistory), \
#                             ))
#unittest.TextTestRunner(verbosity=2).run(alltests)