Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/tests/coretests.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/sugar/tutorius/tests/coretests.py')
-rw-r--r--src/sugar/tutorius/tests/coretests.py41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/sugar/tutorius/tests/coretests.py b/src/sugar/tutorius/tests/coretests.py
index 5f91a64..c27846d 100644
--- a/src/sugar/tutorius/tests/coretests.py
+++ b/src/sugar/tutorius/tests/coretests.py
@@ -18,7 +18,7 @@
Core Tests
This module contains all the tests that pertain to the usage of the Tutorius
-Core. This means that the the Finite State Machine, States and all the
+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
@@ -29,7 +29,7 @@ and event filters. Those are in their separate test module
import unittest
import logging
-from sugar.tutorius.actions import Action, ClickAction, TypeTextAction
+from sugar.tutorius.actions import Action, OnceWrapper, ClickAction, TypeTextAction
from sugar.tutorius.core import *
from sugar.tutorius.filters import *
@@ -49,6 +49,14 @@ class SimpleTutorial(Tutorial):
def set_state(self, name):
self.current_state_name = name
+class TutorialWithFSM(Tutorial):
+ """
+ Fake tutorial, but associated with a FSM.
+ """
+ def __init__(self, start_name="INIT", fsm=None):
+ Tutorial.__init__(self, start_name, fsm)
+ self.activity = activity.Activity()
+
class TrueWhileActiveAction(Action):
"""
This action's active member is set to True after a do and to False after
@@ -483,7 +491,6 @@ class FSMTest(unittest.TestCase):
except Exception:
assert False, "Removing a non-existing state dit not throw the right kind of exception"
-
# Now try removing the second state
fsm.remove_state("second")
@@ -502,6 +509,33 @@ class FSMTest(unittest.TestCase):
assert "second" not in fsm.get_following_states("third"),\
"The link to second from third still exists after removal"
+ def test_set_same_state(self):
+ fsm = FiniteStateMachine("Set same state")
+
+ st1 = State("INIT")
+ st1.add_action(CountAction())
+
+ fsm.add_state(st1)
+
+ tut = SimpleTutorial()
+
+ fsm.set_tutorial(tut)
+
+ fsm.set_state("INIT")
+
+ assert fsm.get_state_by_name("INIT").get_action_list()[0].do_count == 1, \
+ "The action was not triggered on 'INIT'"
+
+ fsm.set_state("INIT")
+
+ do_count = fsm.get_state_by_name("INIT").get_action_list()[0].do_count
+ assert fsm.get_state_by_name("INIT").get_action_list()[0].do_count == 1, \
+ "The action was triggered a second time, do_count = %d"%do_count
+
+ undo_count = fsm.get_state_by_name("INIT").get_action_list()[0].undo_count
+ assert fsm.get_state_by_name("INIT").get_action_list()[0].undo_count == 0,\
+ "The action has been undone unappropriately, undo_count = %d"%undo_count
+
class FSMExplorationTests(unittest.TestCase):
def setUp(self):
self.buildFSM()
@@ -556,6 +590,7 @@ class FSMExplorationTests(unittest.TestCase):
self.validate_previous_states("Third", ("INIT", "Second"))
self.validate_previous_states("Fourth", ("Second"))
+
if __name__ == "__main__":
unittest.main()