Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/tutorius/tests')
-rwxr-xr-xsrc/sugar/tutorius/tests/run-tests.py3
-rw-r--r--src/sugar/tutorius/tests/serializertests.py105
2 files changed, 102 insertions, 6 deletions
diff --git a/src/sugar/tutorius/tests/run-tests.py b/src/sugar/tutorius/tests/run-tests.py
index 1fc534e..042b10e 100755
--- a/src/sugar/tutorius/tests/run-tests.py
+++ b/src/sugar/tutorius/tests/run-tests.py
@@ -51,8 +51,7 @@ if __name__=='__main__':
suite.addTests(unittest.findTestCases(filterstests))
suite.addTests(unittest.findTestCases(constraintstests))
suite.addTests(unittest.findTestCases(propertiestests))
- suite.addTests(unittest.findTestCases(serializertests))
-
+ suite.addTests(unittest.findTestCases(serializertests))
runner = unittest.TextTestRunner()
runner.run(suite)
coverage.stop()
diff --git a/src/sugar/tutorius/tests/serializertests.py b/src/sugar/tutorius/tests/serializertests.py
index a53e196..2a743e1 100644
--- a/src/sugar/tutorius/tests/serializertests.py
+++ b/src/sugar/tutorius/tests/serializertests.py
@@ -28,21 +28,118 @@ import unittest
import logging
import linecache
import os
-import cPickle as pickle
+import shutil
from sugar.tutorius import gtkutils, overlayer
from sugar.tutorius.core import Tutorial, State, FiniteStateMachine
from sugar.tutorius.actions import DialogMessage, OnceWrapper, BubbleMessage
from sugar.tutorius.filters import GtkWidgetEventFilter, TimerEvent
+from sugar.tutorius.bundler import *
+from uuid import *
+import rpdb2
-# Helper classes to help testing
-
+class SerializerInterfaceTest(unittest.TestCase):
+ """
+ For completeness' sake.
+ """
+ def test_save(self):
+ ser = Serializer()
+
+ try:
+ ser.save_fsm(None)
+ assert False, "save_fsm() should throw an unimplemented error"
+ except:
+ pass
+
+ def test_load(self):
+ ser = Serializer()
+
+ try:
+ ser.load_fsm(str(uuid.uuid1))
+ assert False, "load_fsm() should throw an unimplemented error"
+ except:
+ pass
+class XMLSerializerTest(unittest.TestCase):
+ """
+ Tests the transformation of XML to FSM, then back.
+ """
+ def setUp(self):
+ # Create the sample FSM
+ self.fsm = FiniteStateMachine("testingMachine")
+
+ # Add a few states
+ act1 = BubbleMessage(message="Hi", pos=[300, 450])
+ ev1 = GtkWidgetEventFilter("0.12.31.2.2", "clicked", "Second")
+ act2 = BubbleMessage(message="Second message", pos=[250, 150], tailpos=[1,2])
+
+ st1 = State("INIT")
+ st1.add_action(act1)
+
+ st2 = State("Second")
+
+ st2.add_action(act2)
+
+ self.fsm.add_state(st1)
+ self.fsm.add_state(st2)
+
+ self.uuid = uuid1()
+
+
+ def test_save(self, remove=True):
+ """
+ Writes an FSM to disk, then compares the file to the expected results.
+ "Remove" boolean argument specify if the test data must be removed or not
+ """
+ # Make the serializer believe the test is in a activity path
+ testpath = "/tmp/testdata/"
+ os.environ["SUGAR_BUNDLE_PATH"] = testpath
+ os.environ["SUGAR_PREFIX"] = testpath
+## os.mkdir(sugar.tutorius.bundler._get_store_root())
+ xml_ser = XMLSerializer()
+ os.makedirs(os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)))
+ #rpdb2.start_embedded_debugger('flakyPass')
+ xml_ser.save_fsm(self.fsm, "fsm.xml", os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)))
+
+ #Remove test file and path
+ if remove == True:
+ os.remove(os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)) + "/fsm.xml")
+ if os.path.isdir(testpath):
+ shutil.rmtree(testpath)
+
+ def test_save_and_load(self):
+ """
+ Load up the written FSM and compare it with the object representation.
+ """
+ self.test_save(False)
+ testpath = "/tmp/testdata/"
+ #rpdb2.start_embedded_debugger('flakyPass')
+ xml_ser = XMLSerializer()
+
+ # This interface needs to be redone... It's not clean because there is
+ # a responsibility mixup between the XML reader and the bundler.
+ loaded_fsm = xml_ser.load_fsm(str(self.uuid))
+
+ # Compare the two FSMs
+ assert loaded_fsm._states.get("INIT").name == self.fsm._states.get("INIT").name, \
+ 'FSM underlying dictionary differ from original to pickled/reformed one'
+ assert loaded_fsm._states.get("Second").name == self.fsm._states.get("Second").name, \
+ 'FSM underlying dictionary differ from original to pickled/reformed one'
+ assert loaded_fsm._states.get("INIT").get_action_list()[0].message.value == \
+ self.fsm._states.get("INIT").get_action_list()[0].message.value, \
+ 'FSM underlying State underlying Action differ from original to reformed one'
+ assert len(loaded_fsm.get_action_list()) == 0, "FSM should not have any actions on itself"
+
+ os.remove(os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)) + "/fsm.xml")
+ if os.path.isdir(testpath):
+ shutil.rmtree(testpath)
+# Helper classes to help testing
class SerializerTest(unittest.TestCase):
"""
+
This class has to test the Serializer methods as well as the expected
functionality.
"""
@@ -119,4 +216,4 @@ class SerializerTest(unittest.TestCase):
if __name__ == "__main__":
- unittest.main() \ No newline at end of file
+ unittest.main()