Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/test_enumerator.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_enumerator.py')
-rw-r--r--test_enumerator.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/test_enumerator.py b/test_enumerator.py
new file mode 100644
index 0000000..e4af604
--- /dev/null
+++ b/test_enumerator.py
@@ -0,0 +1,97 @@
+# coding: UTF8
+# Copyright 2009 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 sys
+import cairo
+import ka_debug
+import ka_factory
+import ka_random
+import ka_extensionpoint
+import model_protozoon
+import model_constraintpool
+import model_layer
+
+class VariantEnumerator(object):
+
+ def explain_permutation(self):
+ ka_random.set_flurry(9)
+ cpool = model_constraintpool.ConstraintPool.get_pool()
+
+ for operator_key in model_layer.Layer.OPERATORS:
+ for merger_key in ka_factory.get_factory('merger').keys():
+ cpool.clear_all()
+ cpool.set('/Protozoon', 'layernumberofconstraint', [4, 4])
+ cpool.set('/Protozoon', 'layertypeconstraint',
+ ['image', 'markovchain'])
+ cpool.set('/Protozoon/ImageLayer', 'operatorconstraint',
+ [operator_key])
+ cpool.set('/Protozoon/MarkovChainLayer', 'operatorconstraint',
+ [operator_key])
+ cpool.set('/Protozoon', 'mergertypeconstraint', merger_key)
+ self._explain_protozon(
+ model_layer.Layer.OPERATOR_NAMES[operator_key], merger_key)
+
+ for layer_key in ka_factory.get_factory('layer').keys():
+ for merger_key in ka_factory.get_factory('merger').keys():
+ cpool.clear_all()
+ cpool.set('/Protozoon', 'layernumberofconstraint', [3, 3])
+ cpool.set('/Protozoon', 'layertypeconstraint', layer_key)
+ cpool.set('/Protozoon', 'mergertypeconstraint', merger_key)
+ cpool.set('/Protozoon/ImageLayer', 'operatorconstraint',
+ [cairo.OPERATOR_OVER])
+ cpool.set('/Protozoon/MarkovChainLayer', 'operatorconstraint',
+ [cairo.OPERATOR_OVER])
+ cpool.set('/Protozoon/ReferencePattern', 'operatorconstraint',
+ [cairo.OPERATOR_OVER])
+ cpool.set('/Protozoon/LetterPress', 'operatorconstraint',
+ [cairo.OPERATOR_OVER])
+ self._explain_protozon(layer_key, merger_key)
+
+ def _explain_protozon(self, key1, key2):
+ a_protozoon = model_protozoon.Protozoon()
+ a_protozoon.randomize()
+
+ base_name = 'index'
+ base_folder = '/dev/shm/'
+ explain_id = '_' + key1 + '_' + key2
+ ep_list = ka_extensionpoint.list_extensions('formater')
+ formater = ka_extensionpoint.create(ep_list[0],
+ base_name,
+ explain_id,
+ base_folder)
+ a_protozoon.explain(formater)
+ file_path = formater.get_pathname('html')
+ formater.write_html_file(file_path)
+
+ def _write_file(self, file_path, page):
+ out_file = None
+ try:
+ out_file = open(file_path, 'w')
+ out_file.write(page)
+ except:
+ print 'failed writing [%s] [%s] [%s]' % \
+ (out_file.name, sys.exc_info()[0], sys.exc_info()[1])
+ finally:
+ if out_file:
+ out_file.close()
+
+def explain():
+ ve = VariantEnumerator()
+ ve.explain_permutation()
+
+if __name__ == '__main__':
+ explain() \ No newline at end of file