Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/enginetests.py80
-rw-r--r--tests/ressources/icon.svg21
-rw-r--r--tests/storetests.py76
-rw-r--r--tests/vaulttests.py239
4 files changed, 259 insertions, 157 deletions
diff --git a/tests/enginetests.py b/tests/enginetests.py
new file mode 100644
index 0000000..2cb2330
--- /dev/null
+++ b/tests/enginetests.py
@@ -0,0 +1,80 @@
+# Copyright (C) 2009, Tutorius.org
+# Copyright (C) 2009, Michael Janelle-Montcalm <michael.jmontcalm@gmail.com>
+#
+# 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 2 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
+"""
+Core Tests
+
+This module contains all the tests that pertain to the usage of the Tutorius
+Core. This means that the Event Filters, the Finite State Machine and all the
+related elements and interfaces are tested here.
+
+Usage of actions and event filters is tested, but not the concrete actions
+and event filters. Those are in their separate test module
+
+"""
+
+import unittest
+
+from copy import deepcopy
+
+from sugar.tutorius.tutorial import Tutorial
+from sugar.tutorius.engine import TutorialRunner
+
+from actiontests import CountAction, FakeEventFilter
+
+class MockProbeMgr(object):
+ def __init__(self):
+ self.action = None
+ self.event = None
+ self.cB = None
+
+ def doCB(self):
+ self.cB(self.event)
+
+ currentActivity = property(fget=lambda s:s, fset=lambda s, v: v)
+
+ def install(self, action, block=False):
+ self.action = action
+
+ def update(self, action, newaction, block=False):
+ self.action = newaction
+
+ def uninstall(self, action, block=False):
+ self.action = None
+
+ def subscribe(self, event, callback):
+ self.event = event
+ self.cB = callback
+ return str(event)
+
+ def unsubscribe(self, address):
+ self.event = address
+
+class TutorialRunnerTest(unittest.TestCase):
+ """
+ This class needs to test the TutorialRunner
+ """
+ def setUp(self):
+ self.pM = MockProbeMgr()
+ self.runner = TutorialRunner(self.pM)
+
+ def tearDown(self):
+ self.runner = None
+ self.pM = None
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/ressources/icon.svg b/tests/ressources/icon.svg
new file mode 100644
index 0000000..bb28f04
--- /dev/null
+++ b/tests/ressources/icon.svg
@@ -0,0 +1,21 @@
+<?xml version="1.0" ?><!-- Created with Inkscape (http://www.inkscape.org/) --><!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd' [
+ <!ENTITY stroke_color "#000000">
+ <!ENTITY fill_color "#ffffff">
+]><svg height="55px" id="svg2393" inkscape:output_extension="org.inkscape.output.svg.inkscape" inkscape:version="0.47pre1 r21720" sodipodi:docname="tutortool.svg" sodipodi:version="0.32" version="1.1" width="55px" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns:svg="http://www.w3.org/2000/svg">
+ <defs id="defs2395">
+ <inkscape:perspective id="perspective2401" inkscape:persp3d-origin="16 : 10.666667 : 1" inkscape:vp_x="0 : 16 : 1" inkscape:vp_y="0 : 1000 : 0" inkscape:vp_z="32 : 16 : 1" sodipodi:type="inkscape:persp3d"/>
+ </defs>
+ <sodipodi:namedview bordercolor="#666666" borderopacity="1.0" id="base" inkscape:current-layer="layer1" inkscape:cx="3.7661233" inkscape:cy="33.132055" inkscape:document-units="px" inkscape:grid-bbox="true" inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:window-height="675" inkscape:window-maximized="0" inkscape:window-width="1057" inkscape:window-x="108" inkscape:window-y="45" inkscape:zoom="3.9590209" pagecolor="#ffffff" showgrid="true"/>
+ <metadata id="metadata2398">
+ <rdf:RDF>
+ <cc:Work rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1" transform="translate(0,23)">
+ <path d="m 38.01548,1.5478747 c 0,7.1837999 -7.3667,13.0141283 -16.443525,13.0141283 -2.269208,0 -8.124729,3.152936 -13.9608513,4.252763 C 13.382177,14.110994 11.434521,11.926642 9.9463815,10.748864 6.9701032,8.3933076 5.1284282,5.1397735 5.1284282,1.5478747 c 0,-7.1837994 7.3666998,-13.0141297 16.4435268,-13.0141297 9.076825,0 16.443525,5.8303303 16.443525,13.0141297 z" id="path2403" sodipodi:nodetypes="cscsssc" style="fill:&fill_color;;fill-opacity:1;fill-rule:nonzero;stroke:&stroke_color;;stroke-width:1.96931934;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
+ <path d="m 50.150276,6.4721386 c 0,2.621116 -1.428036,4.9953144 -3.735846,6.7142344 -1.153905,0.85946 -1.824287,2.434433 1.398853,6.784273 -6.258422,-3.991066 -8.65379,-4.001712 -10.413335,-4.001712 -7.03818,0 -12.750327,-4.254565 -12.750327,-9.4967954 0,-5.2422321 5.712147,-9.4967971 12.750327,-9.4967971 7.038182,0 12.750328,4.254565 12.750328,9.4967971 z" id="path3175" sodipodi:nodetypes="cccsssc" style="fill:&fill_color;;fill-opacity:1;fill-rule:nonzero;stroke:&stroke_color;;stroke-width:1.96931934;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-opacity:1;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"/>
+ </g>
+</svg> \ No newline at end of file
diff --git a/tests/storetests.py b/tests/storetests.py
index 0d1d9af..0c36973 100644
--- a/tests/storetests.py
+++ b/tests/storetests.py
@@ -15,16 +15,18 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import unittest
+import uuid
from tests.utils import skip, catch_unimplemented
+import random
from sugar.tutorius.store import *
-g_tutorial_id = '114db454-b2a1-11de-8cfc-001f5bf747dc'
-g_other_id = '47efc6ee-b2a3-11de-8cfc-001f5bf747dc'
+g_tutorial_id = '4079'
+g_other_id = '4080'
class StoreProxyTest(unittest.TestCase):
def setUp(self):
- self.store = StoreProxy()
+ self.store = StoreProxy("http://bobthebuilder.mine.nu/tutorius/en-US/tutorius")
def tearDown(self):
pass
@@ -39,13 +41,6 @@ class StoreProxyTest(unittest.TestCase):
def test_get_tutorials(self):
self.store.get_tutorials()
- @catch_unimplemented
- def test_get_tutorial_collection(self):
- collection_list = self.store.get_tutorial_collection('top5_rating')
-
- assert isinstance(collection_list, list), "get_tutorial_collection should return a list"
-
- @catch_unimplemented
def test_get_latest_version(self):
version_dict = self.store.get_latest_version([])
@@ -53,21 +48,21 @@ class StoreProxyTest(unittest.TestCase):
@catch_unimplemented
def test_download_tutorial(self):
- tutorial = self.store.download_tutorial(g_tutorial_id)
+ tutorial = self.store.download_tutorial(g_other_id)
assert tutorial is not None
@catch_unimplemented
def test_login(self):
- assert self.store.login("unknown_user", "random_password")
+ assert self.store.login("benoit.tremblay1@gmail.com", "tutorius12")
@catch_unimplemented
def test_register_new_user(self):
+ random_num = str(random.randint(0, 999999999))
user_info = {
- 'name' : "Albert",
- 'last_name' : "The Tester",
- 'location' : 'Mozambique',
- 'email' : 'albertthetester@mozambique.org'
+ 'nickname' : "Albert%s" % (random_num),
+ 'password' : "tutorius12",
+ 'email' : 'albertthetester%s@mozambique.org' % (random_num)
}
assert self.store.register_new_user(user_info)
@@ -76,8 +71,8 @@ class StoreProxyTest(unittest.TestCase):
class StoreProxyLoginTest(unittest.TestCase):
@catch_unimplemented
def setUp(self):
- self.store = StoreProxy()
- self.store.login("unknown_user", "random_password")
+ self.store = StoreProxy("http://bobthebuilder.mine.nu/tutorius/en-US/tutorius")
+ self.store.login("nobody@mozilla.org", "tutorius12")
@catch_unimplemented
def tearDown(self):
@@ -85,10 +80,6 @@ class StoreProxyLoginTest(unittest.TestCase):
if session_id is not None:
self.store.close_session()
-
- @catch_unimplemented
- def test_close_session(self):
- assert self.store.close_session()
@catch_unimplemented
def test_get_session_id(self):
@@ -104,20 +95,47 @@ class StoreProxyLoginTest(unittest.TestCase):
def test_publish(self):
# TODO : We need to send in a real tutorial loaded from
# the Vault
- assert self.store.publish(['This should be a real tutorial...'])
+ tutorial_info = {
+ 'name': 'newtut',
+ 'summary': 'This is a tutorial',
+ 'filename': 'test.xml',
+ 'guid': str(uuid.uuid1()),
+ 'homepage': 'http://google.com',
+ 'version': '1',
+ 'cat1': '17',
+ 'cat2': '18',
+ 'cat3': ''
+ }
+ assert self.store.publish('This should be a real tutorial...', tutorial_info) != -1
@catch_unimplemented
def test_unpublish(self):
- # TODO : We need to send in a real tutorial loaded from
- # the Vault
- self.store.publish([g_tutorial_id, 'Fake tutorial'])
-
assert self.store.unpublish(g_tutorial_id)
+
+ # Republish the tutorial
+ self.store.publish(None, None, g_tutorial_id)
+
+ def test_republish(self):
+ assert self.store.publish(None, None, g_tutorial_id)
@catch_unimplemented
def test_update_published_tutorial(self):
# TODO : Run these tests with files from the Vault
- self.store.publish([g_tutorial_id, 'Fake tutorial'])
+ #self.store.publish([g_tutorial_id, 'Fake tutorial'])
+
+ tutorial_info = {
+ 'name': 'newtut',
+ 'summary': 'This is an updated tutorial',
+ 'filename': 'test.xml',
+ 'homepage': 'http://google.com',
+ 'version': '2',
+ 'cat1': '17',
+ 'cat2': '18',
+ 'cat3': ''
+ }
- assert self.store.update_published_tutorial(g_tutorial_id, [g_tutorial_id, 'This is an updated tutorial'])
+ assert self.store.update_published_tutorial(g_tutorial_id, 'This is an updated tutorial', tutorial_info)
+
+ def test_close_session(self):
+ assert self.store.close_session()
diff --git a/tests/vaulttests.py b/tests/vaulttests.py
index 02c34e8..c6bd852 100644
--- a/tests/vaulttests.py
+++ b/tests/vaulttests.py
@@ -29,9 +29,10 @@ import unittest
import os
import shutil
import zipfile
+import cStringIO
from sugar.tutorius import addon
-from sugar.tutorius.core import State, FiniteStateMachine, Tutorial
+from sugar.tutorius.tutorial import Tutorial
from sugar.tutorius.actions import *
from sugar.tutorius.filters import *
from sugar.tutorius.vault import Vault, XMLSerializer, Serializer, TutorialBundler
@@ -100,18 +101,14 @@ class VaultInterfaceTest(unittest.TestCase):
ini_file2.close()
# Create a dummy fsm
- self.fsm = FiniteStateMachine("testingMachine")
+ self.fsm = Tutorial("TestTutorial1")
# Add a few states
act1 = addon.create('BubbleMessage', message="Hi", position=[300, 450])
ev1 = addon.create('GtkWidgetEventFilter', "0.12.31.2.2", "clicked")
act2 = addon.create('BubbleMessage', message="Second message", position=[250, 150], tail_pos=[1,2])
- st1 = State("INIT")
- st1.add_action(act1)
- st1.add_event_filter(ev1, 'Second')
- st2 = State("Second")
- st2.add_action(act2)
- self.fsm.add_state(st1)
- self.fsm.add_state(st2)
+ self.fsm.add_action("INIT", act1)
+ st2 = self.fsm.add_state((act2,))
+ self.fsm.add_transition("INIT",(ev1, st2))
self.tuto_guid = uuid1()
# Create a dummy metadata dictionnary
@@ -146,7 +143,8 @@ class VaultInterfaceTest(unittest.TestCase):
# Creat a dummy tutorial .xml file
serializer = XMLSerializer()
- serializer.save_fsm(self.fsm, 'tutorial.xml', test_path)
+ with file(os.path.join(test_path, 'tutorial.xml'), 'w') as fsmfile:
+ serializer.save_tutorial(self.fsm, fsmfile)
# Create a dummy tutorial metadata file
self.create_test_metadata_file(os.path.join(test_path, 'meta.ini'), self.tuto_guid)
@@ -238,16 +236,8 @@ class VaultInterfaceTest(unittest.TestCase):
reloaded_tuto = vault.loadTutorial(self.tuto_guid)
# Compare the two FSMs
- reloaded_fsm = reloaded_tuto.state_machine
-
- assert reloaded_fsm._states.get("INIT").name == self.fsm._states.get("INIT").name, \
- 'FSM underlying dictionary differ from original to reformed one'
- assert reloaded_fsm._states.get("Second").name == self.fsm._states.get("Second").name, \
+ assert reloaded_tuto.get_state_dict().keys() == self.fsm.get_state_dict().keys(), \
'FSM underlying dictionary differ from original to reformed one'
- assert reloaded_fsm._states.get("INIT").get_action_list()[0].message == \
- self.fsm._states.get("INIT").get_action_list()[0].message, \
- 'FSM underlying State underlying Action differ from original to reformed one'
- assert len(reloaded_fsm.get_action_list()) == 0, "FSM should not have any actions on itself"
def test_saveTutorial(self):
"""
@@ -256,29 +246,65 @@ class VaultInterfaceTest(unittest.TestCase):
# Save the tutorial in the vault
vault = Vault()
- tutorial = Tutorial('test', self.fsm)
+ tutorial = self.fsm
vault.saveTutorial(tutorial, self.test_metadata_dict)
# Get the tutorial back
reloaded_tuto = vault.loadTutorial(self.save_test_guid)
# Compare the two FSMs
- reloaded_fsm = reloaded_tuto.state_machine
-
- assert reloaded_fsm._states.get("INIT").name == self.fsm._states.get("INIT").name, \
+ assert reloaded_tuto.get_state_dict().keys() == self.fsm.get_state_dict().keys(), \
'FSM underlying dictionary differ from original to reformed one'
- assert reloaded_fsm._states.get("Second").name == self.fsm._states.get("Second").name, \
- 'FSM underlying dictionary differ from original to reformed one'
- assert reloaded_fsm._states.get("INIT").get_action_list()[0].message == \
- self.fsm._states.get("INIT").get_action_list()[0].message, \
- 'FSM underlying State underlying Action differ from original to reformed one'
- assert len(reloaded_fsm.get_action_list()) == 0, "FSM should not have any actions on itself"
# TODO : Compare the initial and reloaded metadata when vault.Query() will accept specifc argument
# (so we can specifiy that we want only the metadata for this particular tutorial
-
-
+
+ def test_add_delete_get_path_resource(self):
+ """
+ This test verify that the vault interface function add_resource succesfully add resource in the vault
+ and return the new resource id. It also test the deletion of the resource.
+ """
+ # Path of an image file in the test folder
+ test_path = os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'tmp')
+ if os.path.isdir(test_path) == True:
+ shutil.rmtree(os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'tmp'))
+ os.makedirs(test_path)
+ file_path = os.path.join(test_path, 'test_resource.svg')
+ resource_file = open(file_path, 'wt')
+ resource_file.write('test')
+ resource_file.close()
+ #image_path = os.path.join(os.getcwd(), 'tests', 'resources', 'icon.svg')
+ #assert os.path.isfile(image_path), 'cannot find the test image file'
+
+ # Create and save a tutorial
+ tutorial = Tutorial('test')
+ Vault.saveTutorial(tutorial, self.test_metadata_dict)
+
+ bundler = TutorialBundler(self.save_test_guid)
+ tuto_path = bundler.get_tutorial_path(self.save_test_guid)
+
+ # add the resource to the tutorial
+ resource_id = Vault.add_resource(self.save_test_guid, file_path)
+
+ # Check that the image file is now in the vault
+ assert os.path.isfile(os.path.join(tuto_path, 'resources', resource_id)), 'image file not found in vault'
+
+ # Check if get_resource_path Vault interface function is working
+ vault_path = Vault.get_resource_path(self.save_test_guid, resource_id)
+
+ assert os.path.isfile(vault_path), 'path returned is not a file'
+ basename, extension = os.path.splitext(vault_path)
+ assert extension == '.svg', 'wrong file path have been returned'
+
+ # Delete the resource
+ Vault.delete_resource(self.save_test_guid, resource_id)
+
+ # Check that the resource is not in the vault anymore
+ assert os.path.isfile(os.path.join(tuto_path, 'resources', resource_id)) == False, 'image file found in vault when it should have been deleted.'
+
+
+
def tearDown(self):
folder = os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'data');
for file in os.listdir(folder):
@@ -298,8 +324,8 @@ class SerializerInterfaceTest(unittest.TestCase):
ser = Serializer()
try:
- ser.save_fsm(None)
- assert False, "save_fsm() should throw an unimplemented error"
+ ser.save_tutorial(None)
+ assert False, "save_tutorial() should throw an unimplemented error"
except:
pass
@@ -307,8 +333,8 @@ class SerializerInterfaceTest(unittest.TestCase):
ser = Serializer()
try:
- ser.load_fsm(str(uuid.uuid1()))
- assert False, "load_fsm() should throw an unimplemented error"
+ ser.load_tutorial(str(uuid.uuid1()))
+ assert False, "load_tutorial() should throw an unimplemented error"
except:
pass
@@ -318,100 +344,61 @@ class XMLSerializerTest(unittest.TestCase):
"""
def setUp(self):
-
- os.environ["SUGAR_BUNDLE_PATH"] = os.path.join(sugar.tutorius.vault._get_store_root(), 'test_bundle_path')
- path = os.path.join(sugar.tutorius.vault._get_store_root(), 'test_bundle_path')
- if os.path.isdir(path) != True:
- os.makedirs(path)
-
# Create the sample FSM
- self.fsm = FiniteStateMachine("testingMachine")
+ self.fsm = Tutorial("TestTutorial1")
# Add a few states
act1 = addon.create('BubbleMessage', message="Hi", position=[300, 450])
ev1 = addon.create('GtkWidgetEventFilter', "0.12.31.2.2", "clicked")
act2 = addon.create('BubbleMessage', message="Second message", position=[250, 150], tail_pos=[1,2])
- st1 = State("INIT")
- st1.add_action(act1)
- st1.add_event_filter(ev1, 'Second')
-
- st2 = State("Second")
-
- st2.add_action(act2)
-
- self.fsm.add_state(st1)
- self.fsm.add_state(st2)
+ self.fsm.add_action("INIT",act1)
+ st2 = self.fsm.add_state((act2,))
+ self.fsm.add_transition("INIT",(ev1, st2))
self.uuid = uuid1()
- # Flag to set to True if the output can be deleted after execution of
- # the test
- self.remove = True
-
def tearDown(self):
"""
- Removes the created files, if need be.
+ Nothing to do anymore.
"""
- if self.remove == True:
- shutil.rmtree(os.path.join(sugar.tutorius.vault._get_store_root(), 'test_bundle_path'))
-
- folder = os.path.join(os.getenv("HOME"),".sugar", 'default', 'tutorius', 'data');
- for file in os.listdir(folder):
- file_path = os.path.join(folder, file)
- shutil.rmtree(file_path)
+ pass
- def create_test_metadata(self, ini_file_path, guid):
- ini_file = open(ini_file_path, 'wt')
- ini_file.write("[GENERAL_METADATA]\n")
- ini_file.write('guid=' + str(guid) + '\n')
- ini_file.write('name=TestTutorial1\n')
- ini_file.write('version=1\n')
- ini_file.write('description=This is a test tutorial 1\n')
- ini_file.write('rating=3.5\n')
- ini_file.write('category=Test\n')
- ini_file.write('publish_state=false\n')
- ini_file.write('[RELATED_ACTIVITIES]\n')
- ini_file.write('org.laptop.TutoriusActivity = 1\n')
- ini_file.write('org.laptop.Writus = 1\n')
- ini_file.close()
-
- def test_save(self):
- """
- 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
- """
- xml_ser = XMLSerializer()
- os.makedirs(os.path.join(sugar.tutorius.vault._get_store_root(), str(self.uuid)))
- xml_ser.save_fsm(self.fsm, sugar.tutorius.vault.TUTORIAL_FILENAME, os.path.join(sugar.tutorius.vault._get_store_root(), str(self.uuid)))
- self.create_test_metadata(os.path.join(sugar.tutorius.vault._get_store_root(), str(self.uuid), 'meta.ini'), self.uuid)
-
+ def create_test_metadata(self, file_obj, guid):
+ file_obj.write("[GENERAL_METADATA]\n")
+ file_obj.write('guid=' + str(guid) + '\n')
+ file_obj.write('name=TestTutorial1\n')
+ file_obj.write('version=1\n')
+ file_obj.write('description=This is a test tutorial 1\n')
+ file_obj.write('rating=3.5\n')
+ file_obj.write('category=Test\n')
+ file_obj.write('publish_state=false\n')
+ file_obj.write('[RELATED_ACTIVITIES]\n')
+ file_obj.write('org.laptop.TutoriusActivity = 1\n')
+ file_obj.write('org.laptop.Writus = 1\n')
def test_save_and_load(self):
"""
+ Writes an FSM to disk, then compares the file to the expected results.
Load up the written FSM and compare it with the object representation.
"""
- self.test_save()
xml_ser = XMLSerializer()
-
- loaded_fsm = xml_ser.load_fsm(str(self.uuid))
+ tuto_file = cStringIO.StringIO()
+ xml_ser.save_tutorial(self.fsm, tuto_file)
+
+ xml_ser = XMLSerializer()
+ load_tuto_file = cStringIO.StringIO(tuto_file.getvalue())
+ loaded_fsm = xml_ser.load_tutorial(load_tuto_file)
# Compare the two FSMs
- assert loaded_fsm._states.get("INIT").name == self.fsm._states.get("INIT").name, \
- 'FSM underlying dictionary differ from original to reformed one'
- assert loaded_fsm._states.get("Second").name == self.fsm._states.get("Second").name, \
- 'FSM underlying dictionary differ from original to reformed one'
- assert loaded_fsm._states.get("INIT").get_action_list()[0].message == \
- self.fsm._states.get("INIT").get_action_list()[0].message, \
- '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"
+ assert loaded_fsm == self.fsm, "Loaded FSM differs from original one"
def test_all_actions(self):
"""
Inserts all the known action types in a FSM, then attempt to load it.
"""
- st = State("INIT")
-
+ fsm = Tutorial("TestActions")
+ tuto_file = cStringIO.StringIO()
act1 = addon.create('BubbleMessage', "Hi!", position=[10,120], tail_pos=[-12,30])
act2 = addon.create('DialogMessage', "Hello again.", position=[120,10])
act3 = addon.create('WidgetIdentifyAction')
@@ -423,26 +410,24 @@ class XMLSerializerTest(unittest.TestCase):
actions = [act1, act2, act3, act4, act5, act6, act7, act8]
for action in actions:
- st.add_action(action)
+ fsm.add_action("INIT", action)
- self.fsm.remove_state("Second")
- self.fsm.remove_state("INIT")
- self.fsm.add_state(st)
-
xml_ser = XMLSerializer()
+ xml_ser.save_tutorial(fsm, tuto_file)
+ load_tuto_file = cStringIO.StringIO(tuto_file.getvalue())
- self.test_save()
-
- reloaded_fsm = xml_ser.load_fsm(str(self.uuid))
-
- # TODO : Cannot do object equivalence, must check equality of all underlying object
- # assert self.fsm == reloaded_fsm, "Expected equivalence before saving vs after loading."
+ reloaded_fsm = xml_ser.load_tutorial(load_tuto_file)
+ # Compare the two FSMs
+ assert reloaded_fsm == fsm, "Loaded FSM differs from original one"
+ assert fsm.get_action_dict() == reloaded_fsm.get_action_dict(), \
+ "Actions should be the same"
def test_all_filters(self):
"""
Inserts all the known action filters in a FSM, then attempt to load it.
"""
- st = State("INIT")
+ fsm = Tutorial("TestFilters")
+ tuto_file = cStringIO.StringIO()
ev1 = addon.create('TimerEvent', 1000)
ev2 = addon.create('GtkWidgetEventFilter', object_id="0.0.1.1.0.0.1", event_name="clicked")
@@ -450,20 +435,18 @@ class XMLSerializerTest(unittest.TestCase):
ev4 = addon.create('GtkWidgetTypeFilter', "0.0.1.1.1.2.3", strokes="acbd")
filters = [ev1, ev2, ev3, ev4]
- for filter in filters:
- st.add_event_filter(filter, 'Second')
+ for efilter in filters:
+ fsm.add_transition("INIT", (efilter, 'END'))
- self.fsm.remove_state("INIT")
- self.fsm.add_state(st)
-
xml_ser = XMLSerializer()
-
- self.test_save()
-
- reloaded_fsm = xml_ser.load_fsm(str(self.uuid))
-
- # TODO : Cannot do object equivalence, must check equality of all underlying object
- # assert self.fsm == reloaded_fsm, "Expected equivalence before saving vs after loading."
+ xml_ser.save_tutorial(fsm, tuto_file)
+ load_tuto_file = cStringIO.StringIO(tuto_file.getvalue())
+
+ reloaded_fsm = xml_ser.load_tutorial(load_tuto_file)
+ # Compare the two FSMs
+ assert reloaded_fsm == fsm, "Loaded FSM differs from original one"
+ assert fsm.get_transition_dict() == reloaded_fsm.get_transition_dict(), \
+ "Transitions should be the same"
class TutorialBundlerTests(unittest.TestCase):
@@ -472,7 +455,7 @@ class TutorialBundlerTests(unittest.TestCase):
This module contains all the tests for the storage mecanisms for tutorials
This mean testing saving and loading tutorial, .ini file management and
- adding ressources to tutorial
+ adding resources to tutorial
"""
def setUp(self):
@@ -513,4 +496,4 @@ class TutorialBundlerTests(unittest.TestCase):
if __name__ == "__main__":
- unittest.main()
+ unittest.main()