Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/sugar/tutorius/tests
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-04-17 04:36:31 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-04-17 04:36:31 (GMT)
commite784a2f0b92ecaf46a77ddca94b31fcc86e0cbae (patch)
tree56e23c87959b877e70614e0692b158eae2fd4fc8 /src/sugar/tutorius/tests
parente3633a2cc4a5aa061172f4962da86ce346151ff8 (diff)
parent544b836dab71d36290d3da5131afaef77c88ccd8 (diff)
Merge branch 'jc_support' into mike
Conflicts: source/external/source/sugar-toolkit/src/sugar/tutorius/tests/coretests.py source/external/source/sugar-toolkit/src/sugar/tutorius/tests/run-tests.py
Diffstat (limited to 'src/sugar/tutorius/tests')
-rw-r--r--src/sugar/tutorius/tests/bundlertests.py65
-rw-r--r--src/sugar/tutorius/tests/coretests.py130
-rwxr-xr-xsrc/sugar/tutorius/tests/run-tests.py5
-rw-r--r--src/sugar/tutorius/tests/serializertests.py122
4 files changed, 318 insertions, 4 deletions
diff --git a/src/sugar/tutorius/tests/bundlertests.py b/src/sugar/tutorius/tests/bundlertests.py
new file mode 100644
index 0000000..8da2310
--- /dev/null
+++ b/src/sugar/tutorius/tests/bundlertests.py
@@ -0,0 +1,65 @@
+# Copyright (C) 2009, Tutorius.org
+# Copyright (C) 2009, Charles-Etienne Carriere <iso.swiffer@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
+"""
+Bundler tests
+
+This module contains all the tests for the storage mecanisms for tutorials
+This mean testing savins and loading tutorial, .ini file management and
+adding ressources to tutorial
+"""
+
+import unittest
+import os
+import uuid
+
+from sugar.tutorius import bundler
+
+class TutorialBundlerTests(unittest.TestCase):
+
+ def setUp(self):
+
+ #generate a test GUID
+ self.test_guid = uuid.uuid1()
+ self.guid_path = os.path.join(bundler._get_store_root(),str(self.test_guid))
+ os.mkdir(self.guid_path)
+
+ self.ini_file = os.path.join(self.guid_path, "meta.ini")
+
+ f = open(self.ini_file,'w')
+ f.write("[GENERAL_METADATA]")
+ f.write(os.linesep)
+ f.write("GUID:")
+ f.write(str(self.test_guid))
+ f.close()
+
+ def tearDown(self):
+ os.remove(self.ini_file)
+ os.rmdir(self.guid_path)
+
+ def test_add_ressource(self):
+ bund = bundler.TutorialBundler(self.test_guid)
+
+ temp_file = open("test.txt",'w')
+ temp_file.write('test')
+ temp_file.close()
+
+ bund.add_resource("test.txt")
+
+ assert os.path.exists(os.path.join(self.guid_path,"test.txt")), "add_ressource did not create the file"
+
+if __name__ == "__main__":
+ unittest.main() \ No newline at end of file
diff --git a/src/sugar/tutorius/tests/coretests.py b/src/sugar/tutorius/tests/coretests.py
index 1d864f9..c27846d 100644
--- a/src/sugar/tutorius/tests/coretests.py
+++ b/src/sugar/tutorius/tests/coretests.py
@@ -29,8 +29,7 @@ and event filters. Those are in their separate test module
import unittest
import logging
-import sugar.activity
-from sugar.tutorius.actions import Action, OnceWrapper
+from sugar.tutorius.actions import Action, OnceWrapper, ClickAction, TypeTextAction
from sugar.tutorius.core import *
from sugar.tutorius.filters import *
@@ -73,6 +72,44 @@ 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 FakeParentWidget():
+ """
+ This class fakes a widet container, it implements the get_children() method
+ """
+ def __init__(self):
+ self._children = []
+
+ def add_child(self, child):
+ self._children.append(child)
+
+ def get_children(self):
+ return self._children
+
@@ -112,7 +149,96 @@ class FakeEventFilter(TriggerEventFilter):
self.tutorial.set_state(event_filter.get_next_state())
+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):
+ 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
+
+
+
+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
+
+ 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"
+
+ 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):
diff --git a/src/sugar/tutorius/tests/run-tests.py b/src/sugar/tutorius/tests/run-tests.py
index 87edd57..1fc534e 100755
--- a/src/sugar/tutorius/tests/run-tests.py
+++ b/src/sugar/tutorius/tests/run-tests.py
@@ -14,7 +14,6 @@ SUBDIRS = ["uam"]
GLOB_PATH = os.path.join(FULL_PATH,"*.py")
import unittest
from glob import glob
-
def report_files():
ret = glob(GLOB_PATH)
for dir in SUBDIRS:
@@ -40,6 +39,7 @@ if __name__=='__main__':
import filterstests
import constraintstests
import propertiestests
+ import serializertests
suite = unittest.TestSuite()
suite.addTests(unittest.findTestCases(coretests))
suite.addTests(unittest.findTestCases(servicestests))
@@ -51,10 +51,10 @@ if __name__=='__main__':
suite.addTests(unittest.findTestCases(filterstests))
suite.addTests(unittest.findTestCases(constraintstests))
suite.addTests(unittest.findTestCases(propertiestests))
+ suite.addTests(unittest.findTestCases(serializertests))
runner = unittest.TextTestRunner()
runner.run(suite)
-
coverage.stop()
coverage.report(report_files())
coverage.erase()
@@ -70,5 +70,6 @@ if __name__=='__main__':
from constraintstests import *
from propertiestests import *
from actiontests import *
+ from serializertests import *
unittest.main()
diff --git a/src/sugar/tutorius/tests/serializertests.py b/src/sugar/tutorius/tests/serializertests.py
new file mode 100644
index 0000000..a53e196
--- /dev/null
+++ b/src/sugar/tutorius/tests/serializertests.py
@@ -0,0 +1,122 @@
+# Copyright (C) 2009, Tutorius.org
+# Copyright (C) 2009, Jean-Christophe Savard <savard.jean.christophe@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
+"""
+Serialization Tests
+
+This module contains all the tests that pertain to the usage of the Tutorius
+Serializer object. This means testing saving a tutorial dictionary to a .tml
+file, loading the list of tutorials for this activity and building chosen
+tutorial.
+"""
+
+import unittest
+
+import logging
+import linecache
+import os
+import cPickle as pickle
+
+from sugar.tutorius import gtkutils, overlayer
+from sugar.tutorius.core import Tutorial, State, FiniteStateMachine
+from sugar.tutorius.actions import DialogMessage, OnceWrapper, BubbleMessage
+from sugar.tutorius.filters import GtkWidgetEventFilter, TimerEvent
+
+
+# Helper classes to help testing
+
+
+
+
+class SerializerTest(unittest.TestCase):
+ """
+ This class has to test the Serializer methods as well as the expected
+ functionality.
+ """
+
+ # Voiding test as it is meant to be used with the pickle serializer,
+ # that was deprecated
+## def test_pickle_integrity(self):
+## """
+## Validates content is uncorrupted trough a pickle file save/load.
+## """
+##
+## # Sample valid FSM dict
+## sampleDict = {
+## "INIT":State("INIT",
+## action_list=[
+## OnceWrapper(BubbleMessage(message="Welcome to the text editor tutorial!\n\n Click on the canvas and type a letter.", pos=[100,100], tailpos=[-10,-20])),
+## ],
+## event_filter_list=[
+## GtkWidgetEventFilter("TEXT","0.0.0.1.0.0.0","key-press-event"),
+## TimerEvent("LOST",15),
+## ],
+## ),
+## "LOST":State("LOST",
+## action_list=[BubbleMessage("Click in the canvas and type on your keyboard", [400, 400]),],
+## event_filter_list=[
+## GtkWidgetEventFilter("TEXT","0.0.0.1.0.0.0","key-press-event"),
+## TimerEvent("INIT",5),
+## ],
+## ),
+## "TEXT":State("TEXT",
+## action_list=[OnceWrapper(BubbleMessage(" You can type more letters if you want!\n\n" +
+## "To proceed to the next step, select your text.\n\n Click and drag over the text!", [200,150])),],
+## event_filter_list=[
+## GtkWidgetEventFilter("SELECTED","0.0.0.1.0.0","text-selected"),
+## ],
+## ),
+## }
+##
+## testpath = "/tmp/testdata/"
+##
+## # Create testdata/ folder if no exists
+## if not os.path.exists(testpath):
+## os.mkdir(testpath)
+##
+## serialize = TutoSerializer()
+##
+## # Make the class believe the test is in a activity path
+## os.environ["SUGAR_ACTIVITY_ROOT"] = testpath
+##
+## fsm = FiniteStateMachine("Test", state_dict=sampleDict)
+##
+## serialize.save_tutorial("Test", "Test", fsm, "serializeTest")
+##
+## fileDict = serialize.load_tuto_list()
+##
+## for filekey, tutorial in fileDict.items():
+## if filekey == "Test":
+## reformedTuto = serialize.build_tutorial(filekey)
+##
+## reformedfsm = reformedTuto.get("Test").state_machine
+##
+## #Tests
+## assert reformedfsm._states.get("INIT").name == fsm._states.get("INIT").name, \
+## 'FSM underlying dictionary differ from original to pickled/reformed one'
+## assert reformedfsm._states.get("LOST").name == fsm._states.get("LOST").name, \
+## 'FSM underlying dictionary differ from original to pickled/reformed one'
+## assert reformedfsm._states.get("TEXT").name == fsm._states.get("TEXT").name, \
+## 'FSM underlying dictionary differ from original to pickled/reformed one'
+##
+##
+## os.remove(testpath + "serializeTest.tml")
+## os.rmdir(testpath)
+## os.rmdir("/tmp")
+
+
+if __name__ == "__main__":
+ unittest.main() \ No newline at end of file