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:
authorJean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-19 21:23:42 (GMT)
committer Jean-Christophe Savard <savard.jean.christophe@gmail.com>2009-04-19 21:23:42 (GMT)
commitb94b444aaab2680bcdc6b85c0a00ed929dd58ef7 (patch)
tree9d379feea8c923c93a62bc193588fad281c79191 /src/sugar/tutorius/tests
parent841ecb1a4b807680cbba283bd6b2594848c6dda9 (diff)
Work on bundler.py and serializertests.py, tests OK
Diffstat (limited to 'src/sugar/tutorius/tests')
-rw-r--r--src/sugar/tutorius/tests/serializertests.py190
1 files changed, 125 insertions, 65 deletions
diff --git a/src/sugar/tutorius/tests/serializertests.py b/src/sugar/tutorius/tests/serializertests.py
index 7a31602..c2aeda1 100644
--- a/src/sugar/tutorius/tests/serializertests.py
+++ b/src/sugar/tutorius/tests/serializertests.py
@@ -34,87 +34,147 @@ 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.tutoserialize import TutoSerializer
+from sugar.tutorius.bundler import *
+from uuid import *
+import rpdb2
-# Helper classes to help testing
-
-
-
-
-class SerializerTest(unittest.TestCase):
+class XMLSerializerTest(unittest.TestCase):
"""
- This class has to test the Serializer methods as well as the expected
- functionality.
+ Tests the transformation of XML to FSM, then back.
"""
+ def setUp(self):
+ # Create the sample FSM
+ self.fsm = FiniteStateMachine("testingMachine")
- def test_pickle_integrity(self):
- """
- Validates content is uncorrupted trough a pickle file save/load.
- """
+ # 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])
- # Sample valid FSM dict
- sampleDict = {
- "INIT":State("INIT",
- action_list=[
- OnceWrapper(BubbleMessage(message="Welcome to the text editor tutorial!\n\n Click on the canvas and type a letter.", pos=[100,100], tailpos=[-10,-20])),
- ],
- event_filter_list=[
- GtkWidgetEventFilter("TEXT","0.0.0.1.0.0.0","key-press-event"),
- TimerEvent("LOST",15),
- ],
- ),
- "LOST":State("LOST",
- action_list=[BubbleMessage("Click in the canvas and type on your keyboard", [400, 400]),],
- event_filter_list=[
- GtkWidgetEventFilter("TEXT","0.0.0.1.0.0.0","key-press-event"),
- TimerEvent("INIT",5),
- ],
- ),
- "TEXT":State("TEXT",
- action_list=[OnceWrapper(BubbleMessage(" You can type more letters if you want!\n\n" +
- "To proceed to the next step, select your text.\n\n Click and drag over the text!", [200,150])),],
- event_filter_list=[
- GtkWidgetEventFilter("SELECTED","0.0.0.1.0.0","text-selected"),
- ],
- ),
- }
-
- testpath = "/tmp/testdata/"
+ st1 = State("INIT")
+ st1.add_action(act1)
- # Create testdata/ folder if no exists
- if not os.path.exists(testpath):
- os.mkdir(testpath)
+ st2 = State("Second")
- serialize = TutoSerializer()
+ st2.add_action(act2)
- # Make the class believe the test is in a activity path
- os.environ["SUGAR_ACTIVITY_ROOT"] = testpath
+ self.fsm.add_state(st1)
+ self.fsm.add_state(st2)
- fsm = FiniteStateMachine("Test", state_dict=sampleDict)
+ self.uuid = uuid1()
+
+ def test_save(self):
+ """
+ Writes an FSM to disk, then compares the file to the expected results.
+ """
+ # Make the class 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)))
- serialize.save_tutorial("Test", "Test", fsm, "serializeTest")
+ # Compare the two files
- fileDict = serialize.load_tuto_list()
+ #Remove test file and path
+## os.remove(testpath + os.path.join(sugar.tutorius.bundler._get_store_root(), str(self.uuid)) + "/fsm.xml")
+## os.removedirs(testpath)
+
+ def test_save_and_load(self):
+ """
+ Load up the written FSM and compare it with the object representation.
+ """
+ self.test_save()
- for filekey, tutorial in fileDict.items():
- if filekey == "Test":
- reformedTuto = serialize.build_tutorial(filekey)
-
- reformedfsm = reformedTuto.get("Test").state_machine
+ #rpdb2.start_embedded_debugger('flakyPass')
+ xml_ser = XMLSerializer()
- #Tests
- assert reformedfsm._states.get("INIT").name == fsm._states.get("INIT").name, \
- 'FSM underlying dictionary differ from original to pickled/reformed one'
- assert reformedfsm._states.get("LOST").name == fsm._states.get("LOST").name, \
- 'FSM underlying dictionary differ from original to pickled/reformed one'
- assert reformedfsm._states.get("TEXT").name == fsm._states.get("TEXT").name, \
- 'FSM underlying dictionary differ from original to pickled/reformed one'
+ # 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
+
+# Helper classes to help testing
+class SerializerTest(unittest.TestCase):
+ """
+ This class has to test the Serializer methods as well as the expected
+ functionality.
+ """
- os.remove(testpath + "serializeTest.tml")
- os.rmdir(testpath)
- os.rmdir("/tmp")
+ # Voiding test as it is meant to be used with the pickle serializer,
+ # that was deprecated
+## def test_pickle_integrity(self):
+## """
+## Validates content is uncorrupted trough a pickle file save/load.
+## """
+##
+## # Sample valid FSM dict
+## sampleDict = {
+## "INIT":State("INIT",
+## action_list=[
+## OnceWrapper(BubbleMessage(message="Welcome to the text editor tutorial!\n\n Click on the canvas and type a letter.", pos=[100,100], tailpos=[-10,-20])),
+## ],
+## event_filter_list=[
+## GtkWidgetEventFilter("TEXT","0.0.0.1.0.0.0","key-press-event"),
+## TimerEvent("LOST",15),
+## ],
+## ),
+## "LOST":State("LOST",
+## action_list=[BubbleMessage("Click in the canvas and type on your keyboard", [400, 400]),],
+## event_filter_list=[
+## GtkWidgetEventFilter("TEXT","0.0.0.1.0.0.0","key-press-event"),
+## TimerEvent("INIT",5),
+## ],
+## ),
+## "TEXT":State("TEXT",
+## action_list=[OnceWrapper(BubbleMessage(" You can type more letters if you want!\n\n" +
+## "To proceed to the next step, select your text.\n\n Click and drag over the text!", [200,150])),],
+## event_filter_list=[
+## GtkWidgetEventFilter("SELECTED","0.0.0.1.0.0","text-selected"),
+## ],
+## ),
+## }
+##
+## testpath = "/tmp/testdata/"
+##
+## # Create testdata/ folder if no exists
+## if not os.path.exists(testpath):
+## os.mkdir(testpath)
+##
+## serialize = TutoSerializer()
+##
+## # Make the class believe the test is in a activity path
+## os.environ["SUGAR_ACTIVITY_ROOT"] = testpath
+##
+## fsm = FiniteStateMachine("Test", state_dict=sampleDict)
+##
+## serialize.save_tutorial("Test", "Test", fsm, "serializeTest")
+##
+## fileDict = serialize.load_tuto_list()
+##
+## for filekey, tutorial in fileDict.items():
+## if filekey == "Test":
+## reformedTuto = serialize.build_tutorial(filekey)
+##
+## reformedfsm = reformedTuto.get("Test").state_machine
+##
+## #Tests
+## assert reformedfsm._states.get("INIT").name == fsm._states.get("INIT").name, \
+## 'FSM underlying dictionary differ from original to pickled/reformed one'
+## assert reformedfsm._states.get("LOST").name == fsm._states.get("LOST").name, \
+## 'FSM underlying dictionary differ from original to pickled/reformed one'
+## assert reformedfsm._states.get("TEXT").name == fsm._states.get("TEXT").name, \
+## 'FSM underlying dictionary differ from original to pickled/reformed one'
+##
+##
+## os.remove(testpath + "serializeTest.tml")
+## os.rmdir(testpath)
+## os.rmdir("/tmp")
if __name__ == "__main__":