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.py174
1 files changed, 126 insertions, 48 deletions
diff --git a/src/sugar/tutorius/tests/coretests.py b/src/sugar/tutorius/tests/coretests.py
index ec730f2..5f91a64 100644
--- a/src/sugar/tutorius/tests/coretests.py
+++ b/src/sugar/tutorius/tests/coretests.py
@@ -18,18 +18,24 @@
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
+Core. This means that the the Finite State Machine, States 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
import logging
-from sugar.tutorius.actions import Action, OnceWrapper
+from sugar.tutorius.actions import Action, ClickAction, TypeTextAction
from sugar.tutorius.core import *
from sugar.tutorius.filters import *
+
+from actiontests import CountAction
+
# Helper classes to help testing
class SimpleTutorial(Tutorial):
"""
@@ -58,21 +64,46 @@ class TrueWhileActiveAction(Action):
def undo(self):
self.active = False
+
+class ClickableWidget():
+ """
+ This class fakes a widget with a clicked() method
+ """
+ def __init__(self):
+ self.click_count = 0
+
+ def clicked(self):
+ self.click_count += 1
+
+class FakeTextEntry():
+ """
+ This class fakes a widget with an insert_text() method
+ """
+ def __init__(self):
+ self.text_lines = []
+ self.last_entered_line = ""
+ self.displayed_text = ""
+
+ def insert_text(self, text, index):
+ self.last_entered_line = text
+ self.text_lines.append(text)
+ self.displayed_text = self.displayed_text[0:index] + text + self.displayed_text[index+1:]
-
-class CountAction(Action):
+class FakeParentWidget():
"""
- This action counts how many times it's do and undo methods get called
+ This class fakes a widet container, it implements the get_children() method
"""
def __init__(self):
- self.do_count = 0
- self.undo_count = 0
+ self._children = []
+
+ def add_child(self, child):
+ self._children.append(child)
+
+ def get_children(self):
+ return self._children
+
- def do(self):
- self.do_count += 1
- def undo(self):
- self.undo_count += 1
class TriggerEventFilter(EventFilter):
"""
@@ -110,49 +141,96 @@ class FakeEventFilter(TriggerEventFilter):
self.tutorial.set_state(event_filter.get_next_state())
-class BaseActionTests(unittest.TestCase):
- def test_do_unimplemented(self):
- act = Action()
- try:
- act.do()
- assert False, "do() should trigger a NotImplemented"
- except NotImplementedError:
- assert True, "do() should trigger a NotImplemented"
+class ClickActionTests(unittest.TestCase):
+ """
+ Test class for click action
+ """
+ def test_do_action(self):
+ activity = FakeParentWidget()
+ widget = ClickableWidget()
+ activity.add_child(widget)
+ ObjectStore().activity = activity
+
+ action = ClickAction("0.0")
+
+ assert widget == ObjectStore().activity.get_children()[0],\
+ "The clickable widget isn't reachable from the object store \
+ the test cannot pass"
+
+ action.do()
+
+ assert widget.click_count == 1, "clicked() should have been called by do()"
+
+ action.do()
+
+ assert widget.click_count == 2, "clicked() should have been called by do()"
def test_undo(self):
- act = Action()
- act.undo()
- assert True, "undo() should never fail on the base action"
-
-
-class OnceWrapperTests(unittest.TestCase):
- def test_onceaction_toggle(self):
- """
- Validate that the OnceWrapper wrapper works properly using the
- CountAction
- """
- act = CountAction()
- wrap = OnceWrapper(act)
-
- assert act.do_count == 0, "do() should not have been called in __init__()"
- assert act.undo_count == 0, "undo() should not have been called in __init__()"
-
- wrap.undo()
-
- assert act.undo_count == 0, "undo() should not be called if do() has not been called"
-
- wrap.do()
- assert act.do_count == 1, "do() should have been called once"
+ activity = FakeParentWidget()
+ widget = ClickableWidget()
+ activity.add_child(widget)
+ ObjectStore().activity = activity
+
+ action = ClickAction("0.0")
+
+ assert widget == ObjectStore().activity.get_children()[0],\
+ "The clickable widget isn't reachable from the object store \
+ the test cannot pass"
+
+ action.undo()
+
+ #There is no undo for this action so the test should not fail
+ assert True
+
+
- wrap.do()
- assert act.do_count == 1, "do() should have been called only once"
+class TypeTextActionTests(unittest.TestCase):
+ """
+ Test class for type text action
+ """
+ def test_do_action(self):
+ activity = FakeParentWidget()
+ widget = FakeTextEntry()
+ activity.add_child(widget)
+ ObjectStore().activity = activity
- wrap.undo()
- assert act.undo_count == 1, "undo() should have been called once"
+ test_text = "This is text"
+
+
+ action = TypeTextAction("0.0", test_text)
+
+ assert widget == ObjectStore().activity.get_children()[0],\
+ "The clickable widget isn't reachable from the object store \
+ the test cannot pass"
+
+ action.do()
+
+ assert widget.last_entered_line == test_text, "insert_text() should have been called by do()"
+
+ action.do()
+
+ assert widget.last_entered_line == test_text, "insert_text() should have been called by do()"
+ assert len(widget.text_lines) == 2, "insert_text() should have been called twice"
- wrap.undo()
- assert act.undo_count == 1, "undo() should have been called only once"
+ def test_undo(self):
+ activity = FakeParentWidget()
+ widget = FakeTextEntry()
+ activity.add_child(widget)
+ ObjectStore().activity = activity
+ test_text = "This is text"
+
+
+ action = TypeTextAction("0.0", test_text)
+
+ assert widget == ObjectStore().activity.get_children()[0],\
+ "The clickable widget isn't reachable from the object store \
+ the test cannot pass"
+
+ action.undo()
+
+ #There is no undo for this action so the test should not fail
+ assert True
# State testing class
class StateTest(unittest.TestCase):