Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sugar/tutorius/actions.py51
-rw-r--r--src/sugar/tutorius/tests/actiontests.py45
-rwxr-xr-xsrc/sugar/tutorius/tests/run-tests.py3
3 files changed, 95 insertions, 4 deletions
diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py
index 12de298..60ccd8b 100644
--- a/src/sugar/tutorius/actions.py
+++ b/src/sugar/tutorius/actions.py
@@ -42,6 +42,13 @@ class Action(object):
"""
pass #Should raise NotImplemented?
+ def get_properties(self):
+ if not hasattr(self, "_props") or self._props is None:
+ self._props = []
+ for i in dir(self.__class__):
+ if type(getattr(self.__class__,i)) is property:
+ self._props.append(i)
+ return self._props
class OnceWrapper(object):
"""
@@ -71,6 +78,9 @@ class OnceWrapper(object):
if self._need_undo:
self._action.undo()
self._need_undo = False
+
+ def get_properties(self):
+ return self._action.get_properties()
class DialogMessage(Action):
"""
@@ -82,9 +92,25 @@ class DialogMessage(Action):
def __init__(self, message, pos=[0,0]):
super(DialogMessage, self).__init__()
self._message = message
- self.position = pos
+ self._position = pos
self._dialog = None
+ def set_message(self, msg):
+ self._message = msg
+
+ def get_message(self):
+ return self._message
+
+ message = property(fget=get_message, fset=set_message)
+
+ def set_pos(self, x, y):
+ self._position = [x, y]
+
+ def get_pos(self):
+ return self._position
+
+ position = property(fget=get_pos, fset=set_pos)
+
def do(self):
"""
Show the dialog
@@ -115,14 +141,31 @@ class BubbleMessage(Action):
def __init__(self, message, pos=[0,0], speaker=None, tailpos=None):
Action.__init__(self)
self._message = message
- self.position = pos
+ self._position = pos
self.overlay = None
self._bubble = None
self._speaker = None
self._tailpos = tailpos
-
+ def set_message(self, msg):
+ self._message = msg
+ def get_message(self):
+ return self._message
+ message = property(fget=get_message, fset=set_message, doc="Message displayed to the user")
+
+ def set_pos(self, x, y):
+ self._position = [x, y]
+ def get_pos(self):
+ return self.position
+ position = property(fget=get_pos, fset=set_pos, doc="Position in [x, y] on the screen")
+
+ def set_tail_pos(self, x, y):
+ self._tailpos = [x, y]
+ def get_tail_pos(self):
+ return self._tailpos
+ tail_pos = property(fget=get_tail_pos, fset=set_tail_pos, doc="Position the tail of the bubble must point to")
+
def do(self):
"""
Show the dialog
@@ -135,7 +178,7 @@ class BubbleMessage(Action):
# draw the overlay.
if not self._bubble:
- x, y = self.position
+ x, y = self._position
# TODO: tails are relative to tailpos. They should be relative to
# the speaking widget. Same of the bubble position.
self._bubble = overlayer.TextBubble(text=self._message,
diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py
new file mode 100644
index 0000000..2a60a65
--- /dev/null
+++ b/src/sugar/tutorius/tests/actiontests.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2009, Tutorius.org
+#
+# 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
+"""
+Action tests
+
+The behavior of the actions must be tested here.
+"""
+
+import unittest
+from sugar.tutorius.actions import *
+
+class PropertyAction(Action):
+ def __init__(self, na):
+ self._a = na
+
+ def set_a(self, na):
+ self._a = na
+
+ def get_a(self):
+ return self._a
+
+ a = property(fget=get_a, fset=set_a)
+
+class PropsTest(unittest.TestCase):
+
+ def test_get_properties(self):
+ prop = PropertyAction(8)
+
+ assert prop.get_properties() == ['a'], "Action does not contain property 'a'"
+
+if __name__ == "__main__":
+ unittest.main() \ No newline at end of file
diff --git a/src/sugar/tutorius/tests/run-tests.py b/src/sugar/tutorius/tests/run-tests.py
index 473e083..2f89c62 100755
--- a/src/sugar/tutorius/tests/run-tests.py
+++ b/src/sugar/tutorius/tests/run-tests.py
@@ -28,6 +28,7 @@ if __name__=='__main__':
import gtkutilstests
import overlaytests
import linear_creatortests
+ import actiontests
suite = unittest.TestSuite()
suite.addTests(unittest.findTestCases(coretests))
@@ -35,6 +36,7 @@ if __name__=='__main__':
suite.addTests(unittest.findTestCases(gtkutilstests))
suite.addTests(unittest.findTestCases(overlaytests))
suite.addTests(unittest.findTestCases(linear_creatortests))
+ suite.addTests(unittest.findTestCases(actiontests))
runner = unittest.TextTestRunner()
runner.run(suite)
@@ -47,5 +49,6 @@ if __name__=='__main__':
from servicestests import *
from gtkutilstests import *
from overlaytests import *
+ from actiontests import *
unittest.main()