Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorerick <erick@sugar-dev-erick.(none)>2009-11-15 02:30:02 (GMT)
committer erick <erick@sugar-dev-erick.(none)>2009-11-15 02:30:02 (GMT)
commit8af49b7f9132fda14476c07eb90bc95e86f1c330 (patch)
tree25dbb7a13805e1087224cebc858ad29fea135ca3 /tests
parent810a5807b48f894d89d0941637270e796b3fbb23 (diff)
Added tests for the engine, added automatic transition support
Diffstat (limited to 'tests')
-rw-r--r--tests/enginetests.py60
1 files changed, 48 insertions, 12 deletions
diff --git a/tests/enginetests.py b/tests/enginetests.py
index 2cb2330..30d68de 100644
--- a/tests/enginetests.py
+++ b/tests/enginetests.py
@@ -1,5 +1,5 @@
# Copyright (C) 2009, Tutorius.org
-# Copyright (C) 2009, Michael Janelle-Montcalm <michael.jmontcalm@gmail.com>
+# Copyright (C) 2009, Erick Lavoie <erick.lavoie@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
@@ -15,11 +15,9 @@
# 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
+Engine 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
@@ -28,12 +26,11 @@ 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 sugar.tutorius.filters import EventFilter
-from actiontests import CountAction, FakeEventFilter
+from actiontests import CountAction
class MockProbeMgr(object):
def __init__(self):
@@ -58,10 +55,16 @@ class MockProbeMgr(object):
def subscribe(self, event, callback):
self.event = event
self.cB = callback
+ self.event.install_handlers(callback)
return str(event)
def unsubscribe(self, address):
- self.event = address
+ self.event = None
+
+class MockEvent(EventFilter):
+ pass
+
+
class TutorialRunnerTest(unittest.TestCase):
"""
@@ -69,12 +72,45 @@ class TutorialRunnerTest(unittest.TestCase):
"""
def setUp(self):
self.pM = MockProbeMgr()
- self.runner = TutorialRunner(self.pM)
+
def tearDown(self):
- self.runner = None
self.pM = None
-
+
+ # Basic interface cases
+ def testOneStateTutorial(self):
+ tutorial = Tutorial("TutorialRunner")
+ state_name = tutorial.add_state()
+ tutorial.update_transition(Tutorial.INITIAL_TRANSITION_NAME,
+ None, state_name)
+ event = MockEvent()
+ tutorial.add_transition(state_name, (event, Tutorial.END))
+
+ runner = TutorialRunner(tutorial, self.pM)
+ runner.start()
+
+ assert runner._state == state_name, "Current state is: %s"%runner._state
+ assert self.pM.action == None
+ assert self.pM.event == event
+
+ event.do_callback()
+ assert runner._state == Tutorial.END, "Current state is: %s"%runner._state
+ assert self.pM.action == None, "Current action is %s"%str(self.pM.action)
+ assert self.pM.event == None, "Current event is %s"%str(self.pM.event)
+
+
+
+ # Limit cases
+ def testEmptyTutorial(self):
+ tutorial = Tutorial("TutorialRunner")
+ runner = TutorialRunner(tutorial, self.pM)
+ runner.start()
+
+ assert runner._state == Tutorial.END, "Current state is: %s"%runner._state
+ assert self.pM.action == None
+ assert self.pM.event == None
+
+ # Error cases
if __name__ == "__main__":
unittest.main()