Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Jourdan <b.vehikel@googlemail.com>2010-03-28 15:33:38 (GMT)
committer Thomas Jourdan <b.vehikel@googlemail.com>2010-03-28 15:33:38 (GMT)
commite9f30ca4732e9aad420bde85e23fb96ef8fb2b0c (patch)
tree7bec979cf73c9c944880f516f24e19598f20703e
parentf0d84904457472f2d0935e9adff3fb84739c598b (diff)
clean up before release
-rw-r--r--ep_page_ancestors.py2
-rw-r--r--ka_debug.py6
-rw-r--r--ka_history.py19
-rw-r--r--ka_status.py6
-rw-r--r--kandidtube.py1
-rw-r--r--model_treenode.py1
-rw-r--r--po/Kandid.pot10
-rw-r--r--test_buildingblocks.py222
-rw-r--r--test_exporter.py43
-rw-r--r--test_history.py97
-rw-r--r--test_model.py526
-rw-r--r--test_pages.py42
-rw-r--r--test_status.py43
-rw-r--r--test_suite.py718
-rw-r--r--test_utils.py34
15 files changed, 1001 insertions, 769 deletions
diff --git a/ep_page_ancestors.py b/ep_page_ancestors.py
index 6283cc8..3093d3d 100644
--- a/ep_page_ancestors.py
+++ b/ep_page_ancestors.py
@@ -122,7 +122,7 @@ class AncestorsController(object):
return 0.5
def _paint_next(self, ctx, xpos, ypos, my_id):
- if my_id is not None:
+ if my_id is not None and self._history.contains(my_id):
ka_debug.info('my_id: ' + my_id)
surface = self._history.get_surface(my_id)
width = surface.get_width() if surface is not None else 200
diff --git a/ka_debug.py b/ka_debug.py
index 9bfcc8c..9456259 100644
--- a/ka_debug.py
+++ b/ka_debug.py
@@ -24,8 +24,7 @@ import time
# default path for testing on local machine
DEBUG_ACTIVITY_PATH = '/home/strom/minimal/activities/Kandid.activity'
DEBUG_PROFILE_PATH = '/home/strom/.sugar/1/'
-DBC_BLACK_LIST = ['activity', 'ka_debug', 'kandidtube', 'setup',
- 'test_suite', 'test_history', 'test_enumerator']
+DBC_BLACK_LIST = ['activity', 'ka_debug', 'kandidtube', 'setup', ]
_logger = None
_start_time = time.time()
_last_clock = 0.0
@@ -110,7 +109,8 @@ if _try_once:
import contract, doctest
def enable_contact(module_name):
"""Enables design by contact for a module."""
- if module_name not in DBC_BLACK_LIST:
+ if module_name not in DBC_BLACK_LIST \
+ and not module_name.startswith('test_'):
a_modul = __import__(module_name)
contract.checkmod(module_name)
doctest.testmod(a_modul)
diff --git a/ka_history.py b/ka_history.py
index 228c07c..46bfa55 100644
--- a/ka_history.py
+++ b/ka_history.py
@@ -15,9 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import gtk
-from gettext import gettext as _
-
class KandidHistory(object):
"""
"""
@@ -34,7 +31,14 @@ class KandidHistory(object):
self.old = 0
def __str__(self):
- return '(' + self.ref_count + ', ' + self.parent1_id + ', ' + self.parent2_id + ')'
+ return '(' \
+ + str(self.ref_count) + ', ' \
+ + (self.parent1_id if self.parent1_id is not None else 'None') \
+ + ', ' \
+ + (self.parent2_id if self.parent2_id is not None else 'None') \
+ + ', ' \
+ + (str(self.surface) if self.surface is not None else 'None') \
+ + ')'
def __init__(self):
"""
@@ -94,13 +98,12 @@ class KandidHistory(object):
while self.surfaces_referenced > 25:
min_id, min_old = None, 2**31
for key, parent in self.parents.iteritems():
- if parent.old < min_old:
+ if parent.surface is not None and parent.old < min_old:
min_id, min_old = key, parent.old
if min_id is not None:
- self.parents.surface = None
+ self.parents[min_id].surface = None
self.surfaces_referenced -= 1
-
-
+
def unlink(self, my_id):
"""Forget an id and free the linked surface.
pre: my_id is not None and my_id.startswith('_')
diff --git a/ka_status.py b/ka_status.py
index 9ddb089..16777c5 100644
--- a/ka_status.py
+++ b/ka_status.py
@@ -146,13 +146,13 @@ class Status(object):
http://linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html
"""
try:
- t = open(_proc_status)
- os_status = t.read()
+ proc = open(_proc_status)
+ os_status = proc.read()
self._set_process_status(os_status, 'Threads:', SUB_THREADS)
self._set_process_status(os_status, 'VmSize:', SUB_VM_SIZE)
self._set_process_status(os_status, 'VmPeak:', SUB_VM_PEAK)
self._set_process_status(os_status, 'VmRSS:', SUB_VM_RSS)
- t.close()
+ proc.close()
except:
# non Linux?
ka_debug.err('scan_os_status [%s] [%s]' % \
diff --git a/kandidtube.py b/kandidtube.py
index 8be7211..9a4c75f 100644
--- a/kandidtube.py
+++ b/kandidtube.py
@@ -22,7 +22,6 @@ import base64
from dbus.service import method, signal
from dbus.gobject_service import ExportedGObject
-#!!import telepathy
import ka_debug
import ka_status
diff --git a/model_treenode.py b/model_treenode.py
index 5aa4b45..3f11417 100644
--- a/model_treenode.py
+++ b/model_treenode.py
@@ -15,7 +15,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import time
import cairo
import random
import ka_debug
diff --git a/po/Kandid.pot b/po/Kandid.pot
index 0dec431..c994955 100644
--- a/po/Kandid.pot
+++ b/po/Kandid.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2010-03-25 21:12+0100\n"
+"POT-Creation-Date: 2010-03-28 16:40+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -148,19 +148,19 @@ msgstr ""
msgid "Seed value for random generator: "
msgstr ""
-#: model_treenode.py:316
+#: model_treenode.py:315
msgid "Details for merging node "
msgstr ""
-#: model_treenode.py:319
+#: model_treenode.py:318
msgid "left background color:"
msgstr ""
-#: model_treenode.py:324
+#: model_treenode.py:323
msgid "right background color:"
msgstr ""
-#: model_treenode.py:330
+#: model_treenode.py:329
msgid "Details for modifying node "
msgstr ""
diff --git a/test_buildingblocks.py b/test_buildingblocks.py
new file mode 100644
index 0000000..39d12b4
--- /dev/null
+++ b/test_buildingblocks.py
@@ -0,0 +1,222 @@
+# 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 ka_extensionpoint
+import model_random
+import model_constraintpool
+import exon_color
+import ka_importer
+import exon_position
+import exon_direction
+import exon_buzzword
+import test_utils
+
+class TestKandidBuildingBlocks(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_merger(self):
+ self._run_mm_test('merger')
+
+ def test_modifier(self):
+ self._run_mm_test('modifier')
+
+ def _run_mm_test(self, key):
+ model_random.set_flurry(9)
+ for flavor in ka_extensionpoint.list_extensions(key):
+ mm1 = ka_extensionpoint.create(flavor, '/')
+ mm1.randomize()
+ mm1.mutate()
+ mm1.swap_places()
+ mm2 = ka_extensionpoint.create(flavor, '/')
+ mm2.randomize()
+ mm2.mutate()
+ mm2.swap_places()
+ mm3 = mm1.crossingover(mm2)
+ mm3.mutate()
+ mm3.swap_places()
+ diff = not (mm3 == mm1 and mm3 == mm2)
+ if not diff:
+ print mm1, mm2, mm3
+ self.assertTrue(diff)
+
+ def test_sampler(self):
+ key = 'sampler'
+ model_random.set_flurry(9)
+ for flavor in ka_extensionpoint.list_extensions(key):
+ mm1 = ka_extensionpoint.create(flavor, '/')
+ mm1.randomize()
+ mm1.mutate()
+ mm1.swap_places()
+ mm2 = ka_extensionpoint.create(flavor, '/')
+ mm2.randomize()
+ mm2.mutate()
+ mm2.swap_places()
+ mm3 = mm1.crossingover(mm2)
+ mm3.mutate()
+ mm3.swap_places()
+ diff = not (mm3 == mm1 and mm3 == mm2)
+ if not diff:
+ print 'no difference found:', key, mm1, mm2, mm3
+ extend = mm3.get_sample_extent()
+ self.assertEqual(2, len(extend))
+ self.assertTrue(0.0 < extend[0] <= 1.0)
+ self.assertTrue(0.0 < extend[1] <= 1.0)
+ points = mm3.get_sample_points()
+ for point in points:
+ self.assertEqual(2, len(point))
+ mm3.explain()
+
+ def test_colorgamut(self):
+ key = 'colorgamut'
+ model_random.set_flurry(9)
+ for flavor in ka_extensionpoint.list_extensions(key):
+ mm1 = ka_extensionpoint.create(flavor, '/')
+ mm1.randomize()
+ mm1.mutate()
+ color1 = mm1.get_randomized_color('/')
+ mm1.mutate_color(color1)
+ self.assertEqual(4, len(color1.rgba))
+ class DummyFormater:
+ def __init__(self):
+ self.a_text = ''
+ def text_item(self, text):
+ self.a_text = text
+ dummy_formater = DummyFormater()
+ mm1.copy().explain(dummy_formater)
+ self.assertTrue(len(dummy_formater.a_text) > 0)
+
+ def test_stamp(self):
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ for theme in ka_importer.get_theme_list():
+ cpool.set('*/themeconstraint',
+ 'themeconstraint', theme)
+ self._run_stamp_breed_test(2)
+ cpool.set('*/themeconstraint',
+ 'hemeconstraint', 'non_existing_theme')
+ self._run_stamp_breed_test(99)
+ cpool.set('*/themeconstraint',
+ 'themeconstraint', ka_importer.get_theme_list())
+ self._run_stamp_breed_test(0)
+
+ def _run_stamp_breed_test(self, max_states):
+ model_random.set_flurry(9)
+ for flavor in ka_extensionpoint.list_extensions('stamp'):
+ mm1 = ka_extensionpoint.create(flavor, '/', max_states)
+ mm1.randomize()
+ mm1.mutate()
+ mm1.swap_places()
+ mm2 = ka_extensionpoint.create(flavor, '/', max_states)
+ mm2.randomize()
+ mm2.mutate()
+ mm2.swap_places()
+ mm3 = mm1.crossingover(mm2)
+ mm3.mutate()
+
+ def test_positionconstraint(self):
+ self._run_ep_constarint_test('position')
+
+ def test_directionconstraint(self):
+ self._run_ep_constarint_test('direction')
+
+ def _run_ep_constarint_test(self, key):
+ for flavor in ka_extensionpoint.list_extensions(key + 'constraint'):
+ constraint = ka_extensionpoint.create(flavor, '/')
+ x_pos, y_pos = 0.1, 0.2
+ x_pos, y_pos = constraint.filter(x_pos, y_pos)
+ x_pos, y_pos = constraint.randomize()
+ x_pos, y_pos = constraint.mutate(x_pos, y_pos)
+ self.assertTrue(isinstance(x_pos, float))
+ self.assertTrue(isinstance(y_pos, float))
+
+ def test_exon_position(self):
+ self._run_exon_test('position', exon_position.Position, 0.5, 0.5)
+
+ def test_exon_direction(self):
+ self._run_exon_test('direction', exon_direction.Direction, 0.3, 0.4)
+
+ def test_exon_buzzword(self):
+ self._run_exon_test('buzzword', exon_buzzword.Buzzword, [u'a', u'b'])
+
+ def _run_exon_test(self, key, constructor, *params):
+ model_random.set_flurry(9)
+ test_utils.neutral()
+
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ for constraint in ka_extensionpoint.list_extensions(key + 'constraint'):
+ cpool.set('/' + key.capitalize(), key + 'constraint', [constraint])
+ element1 = constructor('/', *params)
+ element2 = element1.copy()
+ for dummy in range(32):
+ element3 = element1.crossingover(element2)
+ self.assertEqual(element1, element2)
+ self.assertEqual(element1, element3)
+ equal = True
+ for dummy in range(32):
+ element2.randomize()
+ element2.mutate()
+ element2.swap_places()
+ equal = equal and element1 == element2
+ self.assertFalse(equal)
+ self.assertEqual(element1, element3)
+
+ def test_exon_color(self):
+ model_random.set_flurry(9)
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ cpool.clear_all()
+
+ key = 'color'
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+
+ for constraint in ka_extensionpoint.list_extensions(key + 'constraint'):
+ cpool.set('/' + key.capitalize(), key + 'constraint', [constraint])
+ a_color = exon_color.Color('/', 0.5, 0.5, 0.5, 1.0)
+ self.assertFalse(a_color is a_color.crossingover(\
+ exon_color.Color('/', 0.5, 0.5, 0.5, 1.0)))
+ self.assertEqual(4, len(a_color.copy().rgba))
+ a_color.randomize()
+ self.assertEqual(4, len(a_color.rgba))
+ for dummy in range(32):
+ a_color.mutate()
+ self.assertEqual(4, len(a_color.rgba))
+
+ test_utils.neutral()
+ color1 = exon_color.Color('/', 1.0, 1.0, 1.0, 1.0)
+ color2 = color1.copy()
+ self.assertTrue(color2 is not color1)
+ self.assertTrue(color2 == color1)
+ color1.randomize()
+ self.assertFalse(color2 == color1)
+ for dummy in range(32):
+ color3 = color1.crossingover(color2)
+ self.assertTrue(color3 is not color1)
+ self.assertTrue(color3 is not color2)
+ self.assertTrue(color3 == color1 or color3 == color2)
+ color4 = color3.copy()
+ eql = True
+ for dummy in range(32):
+ color4.mutate()
+ color4.swap_places()
+ eql = eql and color4 == color3
+ self.assertFalse(eql)
+
diff --git a/test_exporter.py b/test_exporter.py
new file mode 100644
index 0000000..fb842ae
--- /dev/null
+++ b/test_exporter.py
@@ -0,0 +1,43 @@
+# 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 ka_extensionpoint
+import model_random
+import model_protozoon
+import ka_debug
+import test_utils
+
+class TestKandidExporter(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_png_exporter(self):
+ model_random.set_flurry(9)
+ test_utils.neutral()
+
+ protozoon = model_protozoon.Protozoon()
+ protozoon.randomize()
+ exporter = ka_extensionpoint.create('exporter_png',
+ protozoon,
+ ka_debug.DEBUG_PROFILE_PATH)
+ exporter.export(32, 32)
diff --git a/test_history.py b/test_history.py
index 1943540..3187910 100644
--- a/test_history.py
+++ b/test_history.py
@@ -16,16 +16,14 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import unittest
-import gtk
-import ka_debug
import ka_history
import cairo
class TestKandidHistory(unittest.TestCase):
def setUp(self):
- pass
+ self.id_count = 0
def tearDown(self):
pass
@@ -65,47 +63,64 @@ class TestKandidHistory(unittest.TestCase):
self.assertFalse(history.contains('_abcd'))
self.assertFalse(history.contains('_abc'))
- def test_treestore(self):
+ def test_history_overflow(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()
+ self._add(6, history)
+ for my_id, parent in history.parents.iteritems():
+ print my_id, parent
-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)
+ 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
- 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()
+# 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()
- self.add(treeview)
- self.show_all()
+#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 TestSuite')
-ka_debug.err('testing error message channel.')
-alltests = unittest.TestSuite((\
- unittest.makeSuite(TestKandidHistory), \
- ))
-unittest.TextTestRunner(verbosity=2).run(alltests)
+#ka_debug.info('starting TestSuite')
+#ka_debug.err('testing error message channel.')
+#alltests = unittest.TestSuite((\
+# unittest.makeSuite(TestKandidHistory), \
+# ))
+#unittest.TextTestRunner(verbosity=2).run(alltests)
diff --git a/test_model.py b/test_model.py
new file mode 100644
index 0000000..ede8f95
--- /dev/null
+++ b/test_model.py
@@ -0,0 +1,526 @@
+# 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 os
+import sys
+import traceback
+import unittest
+import cairo
+import gtk
+import time
+import string
+
+import ka_debug
+import ka_factory
+import ka_task
+import ka_extensionpoint
+import ka_incoming
+import ka_widget
+import ka_importer
+import model_random
+import model_protozoon
+import model_constraintpool
+import model_population
+import model_locus
+import exon_color
+import exon_buzzword
+import exon_direction
+import exon_position
+import ep_page_intro
+
+import test_enumerator
+
+import kandid
+import test_utils
+
+EPSILON = 0.00001
+_test_task_completed_count = 0
+
+class TestKandidModel(unittest.TestCase):
+
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_backward(self):
+ for release in range(2, ka_extensionpoint.revision_number):
+ file_path = kandid.REFFERENCEMODEL + str(release)
+ model = model_population.read_file(file_path)
+ self.assertTrue(model is not None)
+ result = model.copy().dot()
+ # Hope to reach this point without an exception
+ for protozoon in model.protozoans:
+ formater = ka_extensionpoint.create('formater_html', 'index',
+ 'test', '/dev/shm/')
+ class DummyTask:
+ def __init__(self):
+ self.quit = False
+ protozoon.explain(DummyTask(), formater)
+ # Hope to reach this point without an exception
+
+ def test_importer(self):
+ import_path = ka_importer.get_import_path()
+ if os.path.exists(import_path):
+ os.rename(import_path, import_path+str(time.clock()))
+
+ import_path = ka_importer.get_import_path()
+ install_marker = os.path.join(ka_debug.DEBUG_PROFILE_PATH,
+ 'net.sourceforge.kandid/data/collection/install.inf')
+ self._write_file(install_marker, 'v1')
+ ka_importer._post_install()
+ self.assertEqual(os.path.join(ka_debug.DEBUG_PROFILE_PATH,
+ 'net.sourceforge.kandid/data/collection'),
+ import_path)
+ self.assertTrue(os.path.exists(import_path))
+ statinfo = os.stat(import_path+'/segment_of_a_circle/stamp_halfcircle_top.svg')
+ mt = statinfo.st_mtime
+ self.assertTrue('segment_of_a_circle' in ka_importer.get_theme_list())
+ dummy = ka_importer.get_rgb_image_list('')
+ dummy = ka_importer.get_alpha_image_list('')
+ svg_image_list = ka_importer.get_svg_image_list('segment_of_a_circle')
+ self.assertTrue(len(svg_image_list) > 0)
+ print mt
+
+ def test_task(self):
+ global _test_task_completed_count
+ _test_task_completed_count = 0
+ ka_task.GeneratorTask(self.task_1, self.on_completed, 'n1').start()
+ time.sleep(5)
+ self.assertTrue(ka_task.GeneratorTask.is_completed())
+ ka_task.GeneratorTask(self.task_2, self.on_completed, 'n2').start()
+ time.sleep(5)
+ self.assertTrue(ka_task.GeneratorTask.is_completed())
+ #TODO gtk main loop is not running. on_completed will not be executed
+ #self.assertEqual(1, _test_task_completed_count)
+
+ def task_1(self, task, *args, **kwargs):
+ print 'leave 1', _test_task_completed_count
+
+ def task_2(self, task, *args, **kwargs):
+ raise Exception
+ print 'leave 2', _test_task_completed_count
+
+ def on_completed(self, *args):
+ global _test_task_completed_count
+ _test_task_completed_count +=1
+ print 'on_completed', _test_task_completed_count
+
+ def test_protozon_formater(self):
+ model_random.set_flurry(9)
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ cpool.clear_all()
+
+ ep_list = ka_extensionpoint.list_extensions('formater')
+ self.assertTrue(len(ep_list) > 0)
+ for ep_key in ep_list:
+ a_protozoon = model_protozoon.Protozoon()
+ a_protozoon.randomize()
+
+ file_path = self.explain(ep_key, a_protozoon,
+ 'index', '/dev/shm/')
+ exit_code = os.spawnvp(os.P_WAIT, 'tidy', ['tidy', '-i', '-q', '-w', '255', file_path])
+ self.assertEqual(0, exit_code)
+
+ def explain(self, ep_key, a_protozoon, base_name, base_folder):
+ formater = ka_extensionpoint.create(ep_key, base_name,
+ a_protozoon.get_unique_id(),
+ base_folder)
+ class DummyTask:
+ def __init__(self):
+ self.quit = False
+ a_protozoon.explain(DummyTask(), formater)
+ file_path = formater.get_absolutename(ep_key)
+ formater.write_html_file(file_path)
+ return file_path
+
+ def test_locus(self):
+ self.assertEqual('/Locus', model_locus.Locus('/').path)
+ self.assertEqual('/A/Locus', model_locus.Locus('/A').path)
+ self.assertEqual('/A', model_locus.Locus('/A').get_trunk())
+ self.assertEqual('/A/B', model_locus.Locus('/A/B').get_trunk())
+
+ def test_html_formater(self):
+ base_name = 'test_html_formater'
+ base_folder = '/dev/shm/'
+ formater = ka_extensionpoint.create('formater_html', base_name,
+ 'test', base_folder)
+ formater.header('Test title')
+ formater.begin_list('l1')
+ a_text = '&<>'
+ formater.text_item(a_text)
+
+ formater.begin_list('l2')
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ key = 'color'
+ for constraint in ka_extensionpoint.list_extensions(key + 'constraint'):
+ cpool.set('/' + key.capitalize(), key + 'constraint', [constraint])
+ a_color = exon_color.Color('/', 0.5, 0.6, 0.7, 0.8)
+ formater.color_item(a_color, 'Color ' + str(constraint))
+ formater.end_list()
+
+ formater.end_list()
+ formater.footer()
+ file_path = formater.get_absolutename('html')
+ formater.write_html_file(file_path)
+ self.assertEqual(4, len(formater.produced_files_list))
+ self.assertEqual(base_folder+'test/'+base_name+'.html',
+ formater.produced_files_list[3])
+ exit_code = os.spawnvp(os.P_WAIT, 'tidy', ['tidy', '-i', file_path])
+ self.assertEqual(0, exit_code)
+
+ def _write_file(self, file_path, page):
+ out_file = None
+ try:
+ out_file = open(file_path, 'w')
+ out_file.write(page)
+ except:
+ self.fail('failed writing [%s] [%s] [%s]' % \
+ (out_file.name, sys.exc_info()[0], sys.exc_info()[1]))
+ traceback.print_exc(file=sys.__stderr__)
+ finally:
+ if out_file:
+ out_file.close()
+
+ def test_constrain_pool(self):
+ position = exon_position.Position('/', 0.1, 0.2)
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ cpool.get(position, exon_position.POSITION_CONSTRAINT)
+ print cpool
+
+ def test_limit(self):
+ self.assertTrue(model_random.limit(-0.01) == 0.0)
+ self.assertTrue(model_random.limit(0.01) == 0.01)
+ self.assertTrue(model_random.limit(1.01) == 1.0)
+ self.assertTrue(model_random.limit_range(-0.02, -0.01, 0.01) == -0.01)
+ self.assertTrue(model_random.limit_range(0.01, -0.01, 0.01) == 0.01)
+ self.assertTrue(model_random.limit_range(0.011, -0.01, 0.01) == 0.01)
+ self.assertTrue(abs(model_random.cyclic_limit(-0.01) - 0.99) < EPSILON)
+ self.assertTrue(abs(model_random.cyclic_limit(0.01) - 0.01) < EPSILON)
+ self.assertTrue(abs(model_random.cyclic_limit(1.01) - 0.01) < EPSILON)
+ for value in range(-20, 20):
+ self.assertTrue(0.0 <= model_random.limit(0.1 * value) <= 1.0)
+ self.assertTrue(0.0 <= model_random.cyclic_limit(0.1*value) <= 1.0)
+
+ def test_extensionpoint(self):
+# ka_extensionpoint.scann()
+ ep_types = ka_extensionpoint.list_extension_types()
+ self.assertTrue(len(ep_types) > 0)
+
+ ep_list = ka_extensionpoint.list_extensions('colorconstraint')
+ self.assertTrue(len(ep_list) > 0)
+ for ep_key in ep_list:
+ colorconstraint = ka_extensionpoint.create(ep_key, '/')
+ self.assertEqual(4, len(colorconstraint.filter((.5, .5, .5, 1.))))
+
+ def test_deepcopy(self):
+ test_utils.neutral()
+ list1 = [exon_buzzword.Buzzword('/', [u'sugar', u'kandid', u'']), \
+ exon_color.Color('/', 0.1, 0.2, 0.3, 1.0), \
+ exon_direction.Direction('/', 0.1, 0.2), \
+ exon_position.Position('/', 0.1, 0.2), \
+ ]
+ list2 = model_random.copy_list(list1)
+ self.assertEqual(len(list1), len(list2))
+ for index, dummy in enumerate(list1):
+ self.assertEqual(list1[index], list2[index])
+ self.assertTrue(list1[index] is not list2[index])
+
+ def test_random(self):
+ model_random.set_flurry(0)
+ seq = model_random.crossing_sequence(10)
+ for index in range(1, len(seq)):
+ self.assertEqual(seq[0], seq[index])
+ model_random.set_flurry(9)
+
+ def test_classification(self):
+ population_size = 12
+ model = model_population.KandidModel(population_size)
+ self.assertEqual(population_size, len(model.fitness))
+ for fade in [1, 2, population_size - 1]:
+ model.fade_away = fade
+ for i in range(population_size):
+ model.fitness[i] = \
+ (population_size - i - 1) * (1.0 / population_size)
+ self._check_classification(population_size, model)
+ for fit in [0.0, 5.0, 9.0]:
+ for i in range(population_size):
+ model.fitness[i] = fit
+ self._check_classification(population_size, model)
+
+ def _check_classification(self, population_size, model):
+ good, moderate, poor = model.classify()
+ print model.fade_away, len(poor)
+# self.assertEqual(model.fade_away, len(poor))
+ self.assertEqual(population_size, len(good)+len(moderate)+len(poor))
+ self.assertTrue(good[0] in model.protozoans)
+ self.assertFalse(model_population.contains_reference(good[0], moderate))
+ self.assertFalse(model_population.contains_reference(good[0], poor))
+ for mod in moderate:
+ self.assertFalse(model_population.contains_reference(mod, poor))
+ self.assertFalse(model_population.contains_reference(mod, good))
+ for poo in poor:
+ self.assertFalse(model_population.contains_reference(poo, moderate))
+ self.assertFalse(model_population.contains_reference(poo, good))
+
+ def test_layer_factory(self):
+ test_utils.neutral()
+ layer_factory = ka_factory.get_factory('layer')
+ keys = layer_factory.keys()
+ self.assertTrue(layer_factory.count() >= 1)
+ self.assertEqual(len(keys), layer_factory.count())
+ for layer_key in keys:
+ self.assertTrue(layer_factory.create(layer_key, '/') is not None)
+ self.assertTrue(layer_factory.create_random([keys[0]], '/') is not None)
+
+ def test_layer(self):
+ model_random.set_flurry(9)
+ test_utils.neutral()
+
+ layer_factory = ka_factory.get_factory('layer')
+ for layer_key in layer_factory.keys():
+ layer1 = layer_factory.create(layer_key, '/')
+ layer2 = layer1.copy()
+ self.assertTrue(layer2 is not layer1)
+ self.assertTrue(layer2 == layer1)
+ layer1.randomize()
+ layer1.swap_places()
+ if layer2 == layer1:
+ pass
+ self.assertFalse(layer2 == layer1)
+ layer3 = layer1.crossingover(layer2)
+ self.assertTrue(layer3 is not layer1)
+ self.assertTrue(layer3 is not layer2)
+ layer4 = layer3.copy()
+ layer4.mutate()
+ for dummy in range(32):
+ layer4.swap_places()
+# self.assertFalse(layer4 == layer3)
+
+ def test_protozoon(self):
+ model_random.set_flurry(9)
+ test_utils.neutral()
+
+ protozoon1 = model_protozoon.Protozoon()
+ protozoon1.randomize()
+ protozoon2 = protozoon1.copy()
+ self.assertTrue(protozoon2 is not protozoon1)
+ if not protozoon2 == protozoon1:
+ print protozoon2 == protozoon1
+ self.assertTrue(protozoon2 == protozoon1)
+ protozoon1.randomize()
+ protozoon1.swap_places()
+ self.assertFalse(protozoon2 == protozoon1)
+ protozoon3 = protozoon1.crossingover(protozoon2)
+ self.assertTrue(protozoon3 is not protozoon1)
+ self.assertTrue(protozoon3 is not protozoon2)
+ protozoon4 = protozoon3.copy()
+ protozoon4.mutate()
+ for dummy in range(32):
+ protozoon4.swap_places()
+# self.assertFalse(protozoon4 == protozoon3)
+
+ def test_population(self):
+ model = model_population.KandidModel(12)
+ model.set_flurry_rate(9)
+ self.assertEqual(9, model.get_flurry_rate())
+
+ model.randomize()
+ model.reduce_fitness(0)
+ model.raise_fitness(1)
+ model.raise_fitness(2)
+ self.assertEqual(0.0, model.fitness[0])
+ self.assertEqual(9.0, model.fitness[2])
+ self.assertTrue(model.fitness[1] < model.fitness[2])
+
+ for fit in range(len(model.fitness)):
+ model.fitness[fit] = 5.0
+ model.fitness[5] = 0.0
+ model.fitness[1] = 0.0
+ model.fitness[3] = 9.0
+ new_indices = model.breed_generation()
+ self.assertTrue(5 in new_indices)
+ self.assertTrue(1 in new_indices)
+ model.fitness[2] = 0.0
+ new_indices = model.random()
+ self.assertTrue(2 in new_indices)
+
+ model.fitness[7] = 0.0
+ model.fitness[5] = 1.0
+ model.fitness[1] = 1.0
+ protozoon1 = model_protozoon.Protozoon()
+ protozoon1.randomize()
+ self.assertEqual(7, model.replace(protozoon1))
+
+ stored_model = model_population.to_buffer(model)
+
+ protozoon2 = model_protozoon.Protozoon()
+ protozoon2.randomize()
+ model.fitness[7] = 0.0
+ model.replace(protozoon2)
+ self.assertEqual(protozoon2.get_unique_id(),
+ model.protozoans[7].get_unique_id())
+ model = model_population.from_buffer(stored_model)
+ self.assertEqual(protozoon1.get_unique_id(),
+ model.protozoans[7].get_unique_id())
+
+ model.fitness[7] = 1.0
+ new_indices = model.breed_single(7)
+ self.assertEqual(1, len(new_indices))
+ self.assertEqual(7, new_indices[0])
+ self.assertEqual(4.0, model.fitness[7])
+
+ ka_debug.dot_start()
+ result = 'digraph persister_objects { rankdir=LR; ranksep="5.0"; node [shape=none,fontname=Sans, fontsize=9, fixedsize=true, height=0.05, width=1.0];\n'
+ result += model.dot()
+ result += '\n}'
+ plain_file = open(kandid.TESTMODEL+'.dot', 'w')
+ if plain_file:
+ plain_file.write(result)
+ plain_file.close()
+ red_count = result.count('color=red')
+ unicode_count = result.count('"unicode ')
+ self.assertTrue(unicode_count > red_count)
+
+ model_population.write_file(kandid.TESTMODEL, model)
+ recalled_model = model_population.read_file(kandid.TESTMODEL)
+
+ def test_incomming1(self):
+ main_view = gtk.HBox()
+ widget = ka_widget.KandidWidget(main_view)
+ #TODO gtk main loop is not running. KandidIncoming.task_render will not be executed
+ incoming = ka_incoming.KandidIncoming(3, widget.getWidget_tree())
+ self.assertEqual(0, len(incoming.incoming_id))
+ protozoon1 = model_protozoon.Protozoon()
+ protozoon1.randomize()
+ incoming.append_protozoon(protozoon1)
+ self.assertEqual(1, len(incoming.incoming_id))
+ self.assertEqual(protozoon1.get_unique_id(),
+ incoming.at_index(0)[0].get_unique_id())
+ incoming.decline_protozoon(0)
+ self.assertEqual(0, len(incoming.incoming_id))
+
+ def test_incomming3(self):
+ protozoon1 = model_protozoon.Protozoon()
+ protozoon1.randomize()
+ protozoon2 = model_protozoon.Protozoon()
+ protozoon2.randomize()
+ protozoon3 = model_protozoon.Protozoon()
+ protozoon3.randomize()
+
+ capacity = 3
+ main_view = gtk.HBox()
+ widget = ka_widget.KandidWidget(main_view)
+ incoming = ka_incoming.KandidIncoming(capacity, widget.getWidget_tree())
+ self.assertEqual(0, len(incoming.incoming_id))
+
+ self.render_incoming(incoming, capacity)
+ incoming.append_protozoon(protozoon1)
+ self.render_incoming(incoming, capacity)
+ incoming.append_protozoon(protozoon2)
+ self.render_incoming(incoming, capacity)
+ incoming.append_protozoon(protozoon3)
+ self.render_incoming(incoming, capacity)
+ self.assertEqual(3, len(incoming.incoming_id))
+ self.assertEqual(protozoon1.get_unique_id(),
+ incoming.at_index(0)[0].get_unique_id())
+ self.assertEqual(protozoon2.get_unique_id(),
+ incoming.at_index(1)[0].get_unique_id())
+ self.assertEqual(protozoon3.get_unique_id(),
+ incoming.at_index(2)[0].get_unique_id())
+
+ incoming.decline_protozoon(0)
+ self.assertEqual(2, len(incoming.incoming_id))
+ self.assertEqual(protozoon2.get_unique_id(),
+ incoming.at_index(0)[0].get_unique_id())
+ self.assertEqual(protozoon3.get_unique_id(),
+ incoming.at_index(1)[0].get_unique_id())
+
+ incoming.decline_protozoon(1)
+ self.assertEqual(1, len(incoming.incoming_id))
+ self.assertEqual(protozoon2.get_unique_id(),
+ incoming.at_index(0)[0].get_unique_id())
+
+ incoming.accept_protozoon(0)
+ self.assertEqual(0, len(incoming.incoming_id))
+
+ protozoon4 = model_protozoon.Protozoon()
+ protozoon4.randomize()
+ incoming.append_protozoon(protozoon1)
+ incoming.append_protozoon(protozoon2)
+ incoming.append_protozoon(protozoon3)
+ incoming.append_protozoon(protozoon4)
+ self.assertEqual(3, len(incoming.incoming_id))
+ self.assertEqual(protozoon2.get_unique_id(),
+ incoming.at_index(0)[0].get_unique_id())
+ self.assertEqual(protozoon3.get_unique_id(),
+ incoming.at_index(1)[0].get_unique_id())
+ self.assertEqual(protozoon4.get_unique_id(),
+ incoming.at_index(2)[0].get_unique_id())
+
+ def render_incoming(self, incoming, capacity):
+ for index in range(capacity):
+ width, height = 200, 200
+ dummy, ctx = self._create_context(width, height)
+ incoming.draw(index, ctx, width, height)
+
+ def test_renderSVG(self):
+ return #TODO support SVG ????
+ test_utils.neutral()
+
+ width, height = 200, 200
+ surface = cairo.SVGSurface('testoutput_p.svg', width, height)
+ ctx = cairo.Context(surface)
+ protozoon1 = model_protozoon.Protozoon()
+ protozoon1.randomize()
+ protozoon1.render(ctx, width, height)
+
+ layer_factory = ka_factory.get_factory('layer')
+ for strategy in layer_factory.keys():
+ layer = layer_factory.create(strategy, '/')
+ layer.randomize()
+ outname = 'testoutput_' + strategy
+# surface = cairo.SVGSurface(outname + '.svg', width, height)
+ surface, ctx = self._create_context(width, height)
+ layer.render(ctx, width, height)
+ surface.write_to_png(outname + '.png')
+
+ def test_localization(self):
+ locale, territory = ka_widget.KandidWidget.get_localization()
+ for lc in locale:
+ self.assertTrue(lc in string.ascii_lowercase)
+ for tc in territory:
+ self.assertTrue(tc in string.ascii_uppercase)
+ file_path = ep_page_intro.IntroController.get_localized_path(locale,
+ territory)
+ self.assertTrue(file_path.endswith('/Kandid.activity/locale/'
+ + locale + '/intro.html'))
+
+ def test_render2(self):
+ self.assertEqual(0, test_enumerator.explain())
+
+ def _create_context(self, width, height):
+ surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
+ ctx = cairo.Context(surface)
+ ctx.scale(width, height)
+ # paint background
+ ctx.set_operator(cairo.OPERATOR_SOURCE)
+ ctx.set_source_rgb(0.0, 0.0, 0.0)
+ ctx.paint()
+ return surface, ctx
diff --git a/test_pages.py b/test_pages.py
new file mode 100644
index 0000000..531d961
--- /dev/null
+++ b/test_pages.py
@@ -0,0 +1,42 @@
+# 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 gtk
+
+import ka_extensionpoint
+import ka_controller
+
+class TestKandidPages(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_load_pages(self):
+ widget_tree = gtk.glade.XML("kandid.glade")
+ controller = ka_controller.KandidController(widget_tree, '')
+ pages = ka_extensionpoint.list_extensions('page')
+ for page in pages:
+ page_controller = ka_extensionpoint.create(page, controller,
+ widget_tree)
+ page_controller.autoconnect_events()
+ page_controller.localize()
+ page_controller.show()
+ page_controller.close()
diff --git a/test_status.py b/test_status.py
new file mode 100644
index 0000000..bf05386
--- /dev/null
+++ b/test_status.py
@@ -0,0 +1,43 @@
+# 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 ka_status
+
+class TestKandidStatus(unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_status(self):
+ status = ka_status.Status.instance()
+ status.set(ka_status.TOPIC_TASK,
+ ka_status.SUB_UNFINISHED,
+ '5')
+ self.assertTrue(status.isDirty())
+ status.set(ka_status.TOPIC_COLLABORATION,
+ ka_status.SUB_BUDDIES_JOINED, '2')
+ self.assertTrue(status.recall().find('Running: Kandid, release v5, DoB activated') >= 0)
+ self.assertFalse(status.isDirty())
+
+ def test_os_status(self):
+ status = ka_status.Status.instance()
+ status.scan_os_status()
+ self.assertTrue(status.recall().find('Resident set size:') >= 0)
diff --git a/test_suite.py b/test_suite.py
index 21963ea..3b9ed47 100644
--- a/test_suite.py
+++ b/test_suite.py
@@ -15,721 +15,27 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-import os
-import sys
-import traceback
import unittest
-import cairo
import gtk
-import time
-import string
import ka_debug
-import ka_factory
-import ka_task
-import ka_extensionpoint
-import ka_incoming
-import ka_widget
-import ka_status
-import ka_importer
-import ka_controller
-import model_random
-import model_protozoon
-import model_constraintpool
-import model_population
-import model_locus
-import exon_color
-import exon_buzzword
-import exon_direction
-import exon_position
-import ep_page_intro
-
-import test_enumerator
-
-import kandid
-import ka_history
-
-EPSILON = 0.00001
-_test_task_completed_count = 0
-
-class TestKandidModel(unittest.TestCase):
-
-
- def setUp(self):
- pass
-
- def tearDown(self):
- pass
-
- def _neutral(self):
- cpool = model_constraintpool.ConstraintPool.get_pool()
- permitted = [x for x in ka_extensionpoint.list_extensions(exon_position.POSITION_CONSTRAINT)
- if x not in ['positionconstraint_centered']]
- cpool.set('*/positionconstraint',
- exon_position.POSITION_CONSTRAINT, permitted)
- permitted = ['colorconstraint_none']
- cpool.set('*/colorconstraint',
- exon_color.COLOR_CONSTRAINT, permitted)
-
-# permitted = [x for x in ka_factory.get_factory('merger').keys()
-# if x not in ['straight', ]]
-# cpool.set('/Protozoon', model_protozoon.MERGER_CONSTRAINT, permitted)
-
- def test_backward(self):
- for release in range(2, ka_extensionpoint.revision_number):
- file_path = kandid.REFFERENCEMODEL + str(release)
- model = model_population.read_file(file_path)
- self.assertTrue(model is not None)
- result = model.copy().dot()
- # Hope to reach this point without an exception
- for protozoon in model.protozoans:
- formater = ka_extensionpoint.create('formater_html', 'index',
- 'test', '/dev/shm/')
- class DummyTask:
- def __init__(self):
- self.quit = False
- protozoon.explain(DummyTask(), formater)
- # Hope to reach this point without an exception
-
- def test_importer(self):
- import_path = ka_importer.get_import_path()
- install_marker = os.path.join(ka_debug.DEBUG_PROFILE_PATH,
- 'net.sourceforge.kandid/data/collection/install.inf')
- self._write_file(install_marker, 'v1')
- ka_importer._post_install()
- self.assertEqual(os.path.join(ka_debug.DEBUG_PROFILE_PATH,
- 'net.sourceforge.kandid/data/collection'),
- import_path)
- self.assertTrue(os.path.exists(import_path))
- statinfo = os.stat(import_path+'/segment_of_a_circle/stamp_halfcircle_top.svg')
- mt = statinfo.st_mtime
- self.assertTrue('segment_of_a_circle' in ka_importer.get_theme_list())
- dummy = ka_importer.get_rgb_image_list('')
- dummy = ka_importer.get_alpha_image_list('')
- svg_image_list = ka_importer.get_svg_image_list('segment_of_a_circle')
- self.assertTrue(len(svg_image_list) > 0)
- print mt
-
- def test_task(self):
- global _test_task_completed_count
- _test_task_completed_count = 0
- ka_task.GeneratorTask(self.task_1, self.on_completed, 'n1').start()
- time.sleep(5)
- self.assertTrue(ka_task.GeneratorTask.is_completed())
- ka_task.GeneratorTask(self.task_2, self.on_completed, 'n2').start()
- time.sleep(5)
- self.assertTrue(ka_task.GeneratorTask.is_completed())
- #TODO gtk main loop is not running. on_completed will not be executed
- #self.assertEqual(1, _test_task_completed_count)
-
- def task_1(self, task, *args, **kwargs):
- print 'leave 1', _test_task_completed_count
-
- def task_2(self, task, *args, **kwargs):
- raise Exception
- print 'leave 2', _test_task_completed_count
-
- def on_completed(self, *args):
- global _test_task_completed_count
- _test_task_completed_count +=1
- print 'on_completed', _test_task_completed_count
-
- def test_merger(self):
- self._run_mm_test('merger')
-
- def test_modifier(self):
- self._run_mm_test('modifier')
-
- def _run_mm_test(self, key):
- model_random.set_flurry(9)
- for flavor in ka_extensionpoint.list_extensions(key):
- mm1 = ka_extensionpoint.create(flavor, '/')
- mm1.randomize()
- mm1.mutate()
- mm1.swap_places()
- mm2 = ka_extensionpoint.create(flavor, '/')
- mm2.randomize()
- mm2.mutate()
- mm2.swap_places()
- mm3 = mm1.crossingover(mm2)
- mm3.mutate()
- mm3.swap_places()
- diff = not (mm3 == mm1 and mm3 == mm2)
- if not diff:
- print mm1, mm2, mm3
- self.assertTrue(diff)
-
- def test_sampler(self):
- key = 'sampler'
- model_random.set_flurry(9)
- for flavor in ka_extensionpoint.list_extensions(key):
- mm1 = ka_extensionpoint.create(flavor, '/')
- mm1.randomize()
- mm1.mutate()
- mm1.swap_places()
- mm2 = ka_extensionpoint.create(flavor, '/')
- mm2.randomize()
- mm2.mutate()
- mm2.swap_places()
- mm3 = mm1.crossingover(mm2)
- mm3.mutate()
- mm3.swap_places()
- diff = not (mm3 == mm1 and mm3 == mm2)
- if not diff:
- print 'no difference found:', key, mm1, mm2, mm3
- extend = mm3.get_sample_extent()
- self.assertEqual(2, len(extend))
- self.assertTrue(0.0 < extend[0] <= 1.0)
- self.assertTrue(0.0 < extend[1] <= 1.0)
- points = mm3.get_sample_points()
- for point in points:
- self.assertEqual(2, len(point))
- mm3.explain()
-
- def test_stamp(self):
- cpool = model_constraintpool.ConstraintPool.get_pool()
- for theme in ka_importer.get_theme_list():
- cpool.set('*/themeconstraint',
- 'themeconstraint', theme)
- self._run_stamp_breed_test(2)
- cpool.set('*/themeconstraint',
- 'hemeconstraint', 'non_existing_theme')
- self._run_stamp_breed_test(99)
- cpool.set('*/themeconstraint',
- 'themeconstraint', ka_importer.get_theme_list())
- self._run_stamp_breed_test(0)
-
- def _run_stamp_breed_test(self, max_states):
- model_random.set_flurry(9)
- for flavor in ka_extensionpoint.list_extensions('stamp'):
- mm1 = ka_extensionpoint.create(flavor, '/', max_states)
- mm1.randomize()
- mm1.mutate()
- mm1.swap_places()
- mm2 = ka_extensionpoint.create(flavor, '/', max_states)
- mm2.randomize()
- mm2.mutate()
- mm2.swap_places()
- mm3 = mm1.crossingover(mm2)
- mm3.mutate()
-
- def test_protozon_formater(self):
- model_random.set_flurry(9)
- cpool = model_constraintpool.ConstraintPool.get_pool()
- cpool.clear_all()
-
- ep_list = ka_extensionpoint.list_extensions('formater')
- self.assertTrue(len(ep_list) > 0)
- for ep_key in ep_list:
- a_protozoon = model_protozoon.Protozoon()
- a_protozoon.randomize()
-
- file_path = self.explain(ep_key, a_protozoon,
- 'index', '/dev/shm/')
- exit_code = os.spawnvp(os.P_WAIT, 'tidy', ['tidy', '-i', '-q', '-w', '255', file_path])
- self.assertEqual(0, exit_code)
-
- def explain(self, ep_key, a_protozoon, base_name, base_folder):
- formater = ka_extensionpoint.create(ep_key, base_name,
- a_protozoon.get_unique_id(),
- base_folder)
- class DummyTask:
- def __init__(self):
- self.quit = False
- a_protozoon.explain(DummyTask(), formater)
- file_path = formater.get_absolutename(ep_key)
- formater.write_html_file(file_path)
- return file_path
-
- def test_locus(self):
- self.assertEqual('/Locus', model_locus.Locus('/').path)
- self.assertEqual('/A/Locus', model_locus.Locus('/A').path)
- self.assertEqual('/A', model_locus.Locus('/A').get_trunk())
- self.assertEqual('/A/B', model_locus.Locus('/A/B').get_trunk())
-
- def test_html_formater(self):
- base_name = 'test_html_formater'
- base_folder = '/dev/shm/'
- formater = ka_extensionpoint.create('formater_html', base_name,
- 'test', base_folder)
- formater.header('Test title')
- formater.begin_list('l1')
- a_text = '&<>'
- formater.text_item(a_text)
-
- formater.begin_list('l2')
- cpool = model_constraintpool.ConstraintPool.get_pool()
- key = 'color'
- for constraint in ka_extensionpoint.list_extensions(key + 'constraint'):
- cpool.set('/' + key.capitalize(), key + 'constraint', [constraint])
- a_color = exon_color.Color('/', 0.5, 0.6, 0.7, 0.8)
- formater.color_item(a_color, 'Color ' + str(constraint))
- formater.end_list()
-
- formater.end_list()
- formater.footer()
- file_path = formater.get_absolutename('html')
- formater.write_html_file(file_path)
- self.assertEqual(4, len(formater.produced_files_list))
- self.assertEqual(base_folder+'test/'+base_name+'.html',
- formater.produced_files_list[3])
- exit_code = os.spawnvp(os.P_WAIT, 'tidy', ['tidy', '-i', file_path])
- self.assertEqual(0, exit_code)
-
- def _write_file(self, file_path, page):
- out_file = None
- try:
- out_file = open(file_path, 'w')
- out_file.write(page)
- except:
- self.fail('failed writing [%s] [%s] [%s]' % \
- (out_file.name, sys.exc_info()[0], sys.exc_info()[1]))
- traceback.print_exc(file=sys.__stderr__)
- finally:
- if out_file:
- out_file.close()
-
- def test_constrain_pool(self):
- position = exon_position.Position('/', 0.1, 0.2)
- cpool = model_constraintpool.ConstraintPool.get_pool()
- cpool.get(position, exon_position.POSITION_CONSTRAINT)
- print cpool
-
- def test_limit(self):
- self.assertTrue(model_random.limit(-0.01) == 0.0)
- self.assertTrue(model_random.limit(0.01) == 0.01)
- self.assertTrue(model_random.limit(1.01) == 1.0)
- self.assertTrue(model_random.limit_range(-0.02, -0.01, 0.01) == -0.01)
- self.assertTrue(model_random.limit_range(0.01, -0.01, 0.01) == 0.01)
- self.assertTrue(model_random.limit_range(0.011, -0.01, 0.01) == 0.01)
- self.assertTrue(abs(model_random.cyclic_limit(-0.01) - 0.99) < EPSILON)
- self.assertTrue(abs(model_random.cyclic_limit(0.01) - 0.01) < EPSILON)
- self.assertTrue(abs(model_random.cyclic_limit(1.01) - 0.01) < EPSILON)
- for value in range(-20, 20):
- self.assertTrue(0.0 <= model_random.limit(0.1 * value) <= 1.0)
- self.assertTrue(0.0 <= model_random.cyclic_limit(0.1*value) <= 1.0)
-
- def test_extensionpoint(self):
-# ka_extensionpoint.scann()
- ep_types = ka_extensionpoint.list_extension_types()
- self.assertTrue(len(ep_types) > 0)
-
- ep_list = ka_extensionpoint.list_extensions('colorconstraint')
- self.assertTrue(len(ep_list) > 0)
- for ep_key in ep_list:
- colorconstraint = ka_extensionpoint.create(ep_key, '/')
- self.assertEqual(4, len(colorconstraint.filter((.5, .5, .5, 1.))))
-
- def test_deepcopy(self):
- self._neutral()
- list1 = [exon_buzzword.Buzzword('/', [u'sugar', u'kandid', u'']), \
- exon_color.Color('/', 0.1, 0.2, 0.3, 1.0), \
- exon_direction.Direction('/', 0.1, 0.2), \
- exon_position.Position('/', 0.1, 0.2), \
- ]
- list2 = model_random.copy_list(list1)
- self.assertEqual(len(list1), len(list2))
- for index, dummy in enumerate(list1):
- self.assertEqual(list1[index], list2[index])
- self.assertTrue(list1[index] is not list2[index])
-
- def test_random(self):
- model_random.set_flurry(0)
- seq = model_random.crossing_sequence(10)
- for index in range(1, len(seq)):
- self.assertEqual(seq[0], seq[index])
- model_random.set_flurry(9)
-
- def test_positionconstraint(self):
- self._run_ep_constarint_test('position')
-
- def test_directionconstraint(self):
- self._run_ep_constarint_test('direction')
-
- def _run_ep_constarint_test(self, key):
- for flavor in ka_extensionpoint.list_extensions(key + 'constraint'):
- constraint = ka_extensionpoint.create(flavor, '/')
- x_pos, y_pos = 0.1, 0.2
- x_pos, y_pos = constraint.filter(x_pos, y_pos)
- x_pos, y_pos = constraint.randomize()
- x_pos, y_pos = constraint.mutate(x_pos, y_pos)
- self.assertTrue(isinstance(x_pos, float))
- self.assertTrue(isinstance(y_pos, float))
-
- def test_classification(self):
- population_size = 12
- model = model_population.KandidModel(population_size)
- self.assertEqual(population_size, len(model.fitness))
- for fade in [1, 2, population_size - 1]:
- model.fade_away = fade
- for i in range(population_size):
- model.fitness[i] = \
- (population_size - i - 1) * (1.0 / population_size)
- self._check_classification(population_size, model)
- for fit in [0.0, 5.0, 9.0]:
- for i in range(population_size):
- model.fitness[i] = fit
- self._check_classification(population_size, model)
-
- def _check_classification(self, population_size, model):
- good, moderate, poor = model.classify()
- print model.fade_away, len(poor)
-# self.assertEqual(model.fade_away, len(poor))
- self.assertEqual(population_size, len(good)+len(moderate)+len(poor))
- self.assertTrue(good[0] in model.protozoans)
- self.assertFalse(model_population.contains_reference(good[0], moderate))
- self.assertFalse(model_population.contains_reference(good[0], poor))
- for mod in moderate:
- self.assertFalse(model_population.contains_reference(mod, poor))
- self.assertFalse(model_population.contains_reference(mod, good))
- for poo in poor:
- self.assertFalse(model_population.contains_reference(poo, moderate))
- self.assertFalse(model_population.contains_reference(poo, good))
-
- def test_exon_position(self):
- self._run_exon_test('position', exon_position.Position, 0.5, 0.5)
-
- def test_exon_direction(self):
- self._run_exon_test('direction', exon_direction.Direction, 0.3, 0.4)
-
- def test_exon_buzzword(self):
- self._run_exon_test('buzzword', exon_buzzword.Buzzword, [u'a', u'b'])
-
- def _run_exon_test(self, key, constructor, *params):
- model_random.set_flurry(9)
- self._neutral()
-
- cpool = model_constraintpool.ConstraintPool.get_pool()
- for constraint in ka_extensionpoint.list_extensions(key + 'constraint'):
- cpool.set('/' + key.capitalize(), key + 'constraint', [constraint])
- element1 = constructor('/', *params)
- element2 = element1.copy()
- for dummy in range(32):
- element3 = element1.crossingover(element2)
- self.assertEqual(element1, element2)
- self.assertEqual(element1, element3)
- equal = True
- for dummy in range(32):
- element2.randomize()
- element2.mutate()
- element2.swap_places()
- equal = equal and element1 == element2
- self.assertFalse(equal)
- self.assertEqual(element1, element3)
-
- def test_exon_color(self):
- model_random.set_flurry(9)
- cpool = model_constraintpool.ConstraintPool.get_pool()
- cpool.clear_all()
-
- key = 'color'
- cpool = model_constraintpool.ConstraintPool.get_pool()
-
- for constraint in ka_extensionpoint.list_extensions(key + 'constraint'):
- cpool.set('/' + key.capitalize(), key + 'constraint', [constraint])
- a_color = exon_color.Color('/', 0.5, 0.5, 0.5, 1.0)
- self.assertFalse(a_color is a_color.crossingover(\
- exon_color.Color('/', 0.5, 0.5, 0.5, 1.0)))
- self.assertEqual(4, len(a_color.copy().rgba))
- a_color.randomize()
- self.assertEqual(4, len(a_color.rgba))
- for dummy in range(32):
- a_color.mutate()
- self.assertEqual(4, len(a_color.rgba))
-
- self._neutral()
- color1 = exon_color.Color('/', 1.0, 1.0, 1.0, 1.0)
- color2 = color1.copy()
- self.assertTrue(color2 is not color1)
- self.assertTrue(color2 == color1)
- color1.randomize()
- self.assertFalse(color2 == color1)
- for dummy in range(32):
- color3 = color1.crossingover(color2)
- self.assertTrue(color3 is not color1)
- self.assertTrue(color3 is not color2)
- self.assertTrue(color3 == color1 or color3 == color2)
- color4 = color3.copy()
- eql = True
- for dummy in range(32):
- color4.mutate()
- color4.swap_places()
- eql = eql and color4 == color3
- self.assertFalse(eql)
-
- def test_layer_factory(self):
- self._neutral()
- layer_factory = ka_factory.get_factory('layer')
- keys = layer_factory.keys()
- self.assertTrue(layer_factory.count() >= 1)
- self.assertEqual(len(keys), layer_factory.count())
- for layer_key in keys:
- self.assertTrue(layer_factory.create(layer_key, '/') is not None)
- self.assertTrue(layer_factory.create_random([keys[0]], '/') is not None)
-
- def test_layer(self):
- model_random.set_flurry(9)
- self._neutral()
-
- layer_factory = ka_factory.get_factory('layer')
- for layer_key in layer_factory.keys():
- layer1 = layer_factory.create(layer_key, '/')
- layer2 = layer1.copy()
- self.assertTrue(layer2 is not layer1)
- self.assertTrue(layer2 == layer1)
- layer1.randomize()
- layer1.swap_places()
- if layer2 == layer1:
- pass
- self.assertFalse(layer2 == layer1)
- layer3 = layer1.crossingover(layer2)
- self.assertTrue(layer3 is not layer1)
- self.assertTrue(layer3 is not layer2)
- layer4 = layer3.copy()
- layer4.mutate()
- for dummy in range(32):
- layer4.swap_places()
-# self.assertFalse(layer4 == layer3)
-
- def test_protozoon(self):
- model_random.set_flurry(9)
- self._neutral()
-
- protozoon1 = model_protozoon.Protozoon()
- protozoon1.randomize()
- protozoon2 = protozoon1.copy()
- self.assertTrue(protozoon2 is not protozoon1)
- if not protozoon2 == protozoon1:
- print protozoon2 == protozoon1
- self.assertTrue(protozoon2 == protozoon1)
- protozoon1.randomize()
- protozoon1.swap_places()
- self.assertFalse(protozoon2 == protozoon1)
- protozoon3 = protozoon1.crossingover(protozoon2)
- self.assertTrue(protozoon3 is not protozoon1)
- self.assertTrue(protozoon3 is not protozoon2)
- protozoon4 = protozoon3.copy()
- protozoon4.mutate()
- for dummy in range(32):
- protozoon4.swap_places()
-# self.assertFalse(protozoon4 == protozoon3)
-
- def test_population(self):
- model = model_population.KandidModel(12)
- model.set_flurry_rate(9)
- self.assertEqual(9, model.get_flurry_rate())
-
- model.randomize()
- model.reduce_fitness(0)
- model.raise_fitness(1)
- model.raise_fitness(2)
- self.assertEqual(0.0, model.fitness[0])
- self.assertEqual(9.0, model.fitness[2])
- self.assertTrue(model.fitness[1] < model.fitness[2])
-
- for fit in range(len(model.fitness)):
- model.fitness[fit] = 5.0
- model.fitness[5] = 0.0
- model.fitness[1] = 0.0
- model.fitness[3] = 9.0
- new_indices = model.breed_generation()
- self.assertTrue(5 in new_indices)
- self.assertTrue(1 in new_indices)
- model.fitness[2] = 0.0
- new_indices = model.random()
- self.assertTrue(2 in new_indices)
-
- model.fitness[7] = 0.0
- model.fitness[5] = 1.0
- model.fitness[1] = 1.0
- protozoon1 = model_protozoon.Protozoon()
- protozoon1.randomize()
- self.assertEqual(7, model.replace(protozoon1))
-
- stored_model = model_population.to_buffer(model)
-
- protozoon2 = model_protozoon.Protozoon()
- protozoon2.randomize()
- model.fitness[7] = 0.0
- model.replace(protozoon2)
- self.assertEqual(protozoon2.get_unique_id(),
- model.protozoans[7].get_unique_id())
- model = model_population.from_buffer(stored_model)
- self.assertEqual(protozoon1.get_unique_id(),
- model.protozoans[7].get_unique_id())
-
- model.fitness[7] = 1.0
- new_indices = model.breed_single(7)
- self.assertEqual(1, len(new_indices))
- self.assertEqual(7, new_indices[0])
- self.assertEqual(4.0, model.fitness[7])
-
- ka_debug.dot_start()
- result = 'digraph persister_objects { rankdir=LR; ranksep="5.0"; node [shape=none,fontname=Sans, fontsize=9, fixedsize=true, height=0.05, width=1.0];\n'
- result += model.dot()
- result += '\n}'
- plain_file = open(kandid.TESTMODEL+'.dot', 'w')
- if plain_file:
- plain_file.write(result)
- plain_file.close()
- red_count = result.count('color=red')
- unicode_count = result.count('"unicode ')
- self.assertTrue(unicode_count > red_count)
-
- model_population.write_file(kandid.TESTMODEL, model)
- recalled_model = model_population.read_file(kandid.TESTMODEL)
-
- def test_incomming1(self):
- main_view = gtk.HBox()
- widget = ka_widget.KandidWidget(main_view)
- #TODO gtk main loop is not running. KandidIncoming.task_render will not be executed
- incoming = ka_incoming.KandidIncoming(3, widget.getWidget_tree())
- self.assertEqual(0, len(incoming.incoming_id))
- protozoon1 = model_protozoon.Protozoon()
- protozoon1.randomize()
- incoming.append_protozoon(protozoon1)
- self.assertEqual(1, len(incoming.incoming_id))
- self.assertEqual(protozoon1.get_unique_id(),
- incoming.at_index(0)[0].get_unique_id())
- incoming.decline_protozoon(0)
- self.assertEqual(0, len(incoming.incoming_id))
-
- def test_incomming3(self):
- protozoon1 = model_protozoon.Protozoon()
- protozoon1.randomize()
- protozoon2 = model_protozoon.Protozoon()
- protozoon2.randomize()
- protozoon3 = model_protozoon.Protozoon()
- protozoon3.randomize()
-
- capacity = 3
- main_view = gtk.HBox()
- widget = ka_widget.KandidWidget(main_view)
- incoming = ka_incoming.KandidIncoming(capacity, widget.getWidget_tree())
- self.assertEqual(0, len(incoming.incoming_id))
-
- self.render_incoming(incoming, capacity)
- incoming.append_protozoon(protozoon1)
- self.render_incoming(incoming, capacity)
- incoming.append_protozoon(protozoon2)
- self.render_incoming(incoming, capacity)
- incoming.append_protozoon(protozoon3)
- self.render_incoming(incoming, capacity)
- self.assertEqual(3, len(incoming.incoming_id))
- self.assertEqual(protozoon1.get_unique_id(),
- incoming.at_index(0)[0].get_unique_id())
- self.assertEqual(protozoon2.get_unique_id(),
- incoming.at_index(1)[0].get_unique_id())
- self.assertEqual(protozoon3.get_unique_id(),
- incoming.at_index(2)[0].get_unique_id())
-
- incoming.decline_protozoon(0)
- self.assertEqual(2, len(incoming.incoming_id))
- self.assertEqual(protozoon2.get_unique_id(),
- incoming.at_index(0)[0].get_unique_id())
- self.assertEqual(protozoon3.get_unique_id(),
- incoming.at_index(1)[0].get_unique_id())
-
- incoming.decline_protozoon(1)
- self.assertEqual(1, len(incoming.incoming_id))
- self.assertEqual(protozoon2.get_unique_id(),
- incoming.at_index(0)[0].get_unique_id())
-
- incoming.decline_protozoon(0)
- self.assertEqual(0, len(incoming.incoming_id))
-
- protozoon4 = model_protozoon.Protozoon()
- protozoon4.randomize()
- incoming.append_protozoon(protozoon1)
- incoming.append_protozoon(protozoon2)
- incoming.append_protozoon(protozoon3)
- incoming.append_protozoon(protozoon4)
- self.assertEqual(3, len(incoming.incoming_id))
- self.assertEqual(protozoon2.get_unique_id(),
- incoming.at_index(0)[0].get_unique_id())
- self.assertEqual(protozoon3.get_unique_id(),
- incoming.at_index(1)[0].get_unique_id())
- self.assertEqual(protozoon4.get_unique_id(),
- incoming.at_index(2)[0].get_unique_id())
-
- def render_incoming(self, incoming, capacity):
- for index in range(capacity):
- width, height = 200, 200
- dummy, ctx = self._create_context(width, height)
- incoming.draw(index, ctx, width, height)
-
- def test_renderSVG(self):
- return #TODO support SVG ????
- self._neutral()
-
- width, height = 200, 200
- surface = cairo.SVGSurface('testoutput_p.svg', width, height)
- ctx = cairo.Context(surface)
- protozoon1 = model_protozoon.Protozoon()
- protozoon1.randomize()
- protozoon1.render(ctx, width, height)
-
- layer_factory = ka_factory.get_factory('layer')
- for strategy in layer_factory.keys():
- layer = layer_factory.create(strategy, '/')
- layer.randomize()
- outname = 'testoutput_' + strategy
-# surface = cairo.SVGSurface(outname + '.svg', width, height)
- surface, ctx = self._create_context(width, height)
- layer.render(ctx, width, height)
- surface.write_to_png(outname + '.png')
-
- def test_localization(self):
- locale, territory = ka_widget.KandidWidget.get_localization()
- for lc in locale:
- self.assertTrue(lc in string.ascii_lowercase)
- for tc in territory:
- self.assertTrue(tc in string.ascii_uppercase)
- file_path = ep_page_intro.IntroController.get_localized_path(locale,
- territory)
- self.assertTrue(file_path.endswith('/Kandid.activity/locale/'
- + locale + '/intro.html'))
-
- def test_render2(self):
- self.assertEqual(0, test_enumerator.explain())
-
- def test_status(self):
- status = ka_status.Status()
- status.set(ka_status.TOPIC_TASK,
- ka_status.SUB_UNFINISHED,
- '5')
- self.assertTrue(status.isDirty())
- status.set(ka_status.TOPIC_COLLABORATION,
- ka_status.SUB_BUDDIES_JOINED, '2')
-# expected = '''
-#Collaboration
-# Buddies joined: 2
-#
-#Tasks
-# Unfinished tasks: 5
-#
-#Activity
-# Running: Kandid, release v5, DoB activated
-#'''
-# self.assertEqual(expected, status.recall())
- self.assertTrue(status.recall().find('Running: Kandid, release v5, DoB activated') >= 0)
- self.assertFalse(status.isDirty())
-
- def _create_context(self, width, height):
- surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
- ctx = cairo.Context(surface)
- ctx.scale(width, height)
- # paint background
- ctx.set_operator(cairo.OPERATOR_SOURCE)
- ctx.set_source_rgb(0.0, 0.0, 0.0)
- ctx.paint()
- return surface, ctx
+import test_history
+import test_pages
+import test_buildingblocks
+import test_status
+import test_exporter
+import test_model
ka_debug.info('starting TestSuite')
ka_debug.err('testing error message channel.')
gtk.gdk.threads_init()
alltests = unittest.TestSuite((\
- unittest.makeSuite(TestKandidModel), \
+ unittest.makeSuite(test_buildingblocks.TestKandidBuildingBlocks), \
+ unittest.makeSuite(test_exporter.TestKandidExporter), \
+ unittest.makeSuite(test_status.TestKandidStatus), \
+ unittest.makeSuite(test_history.TestKandidHistory), \
+ unittest.makeSuite(test_pages.TestKandidPages), \
+ unittest.makeSuite(test_model.TestKandidModel), \
))
unittest.TextTestRunner(verbosity=2).run(alltests)
diff --git a/test_utils.py b/test_utils.py
new file mode 100644
index 0000000..5ec8cdb
--- /dev/null
+++ b/test_utils.py
@@ -0,0 +1,34 @@
+# 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 model_constraintpool
+import ka_extensionpoint
+import exon_position
+import exon_color
+
+def neutral():
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+ permitted = [x for x in ka_extensionpoint.list_extensions(exon_position.POSITION_CONSTRAINT)
+ if x not in ['positionconstraint_centered']]
+ cpool.set('*/positionconstraint',
+ exon_position.POSITION_CONSTRAINT, permitted)
+ permitted = ['colorconstraint_none']
+ cpool.set('*/colorconstraint',
+ exon_color.COLOR_CONSTRAINT, permitted)
+
+# permitted = [x for x in ka_factory.get_factory('merger').keys()
+# if x not in ['straight', ]]
+# cpool.set('/Protozoon', model_protozoon.MERGER_CONSTRAINT, permitted)