# 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)