From a4114a946cc7a57c1cfce5760737c3f05425bc86 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 26 Apr 2009 18:55:55 +0000 Subject: Merge branch 'jc' of ssh://mike@bobthebuilder.mine.nu:8080/home/git into jc_support --- (limited to 'src/sugar/tutorius/tests/serializertests.py') diff --git a/src/sugar/tutorius/tests/serializertests.py b/src/sugar/tutorius/tests/serializertests.py index 0b7fabd..75fe8eb 100644 --- a/src/sugar/tutorius/tests/serializertests.py +++ b/src/sugar/tutorius/tests/serializertests.py @@ -28,7 +28,7 @@ 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 @@ -63,10 +63,12 @@ class XMLSerializerTest(unittest.TestCase): self.fsm.add_state(st2) self.uuid = uuid1() + - def test_save(self): + 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/" @@ -78,19 +80,18 @@ class XMLSerializerTest(unittest.TestCase): #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))) - # Compare the two files - + #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) - #Remove test file and path (commented for testing, to uncomment) -## 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() - + self.test_save(False) + testpath = "/tmp/testdata/" #rpdb2.start_embedded_debugger('flakyPass') xml_ser = XMLSerializer() @@ -101,12 +102,21 @@ class XMLSerializerTest(unittest.TestCase): # 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("LOST").name == self.fsm._states.get("Second").name, \ + 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].get_message() == \ + self.fsm._states.get("INIT").get_action_list()[0].get_message(), \ + 'FSM underlying State underlying Action differ from original to reformed one' + + 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. """ -- cgit v0.9.1