Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormike <michael.jmontcalm@gmail.com>2009-04-16 20:52:21 (GMT)
committer mike <michael.jmontcalm@gmail.com>2009-04-16 20:52:21 (GMT)
commite3633a2cc4a5aa061172f4962da86ce346151ff8 (patch)
treee12948a10b6dbb302d4e2fbfd92d8fa92ea2437a
parent0cad6dc96afc2ebd4d03beb14ed01bc155dfa322 (diff)
LP 348570 Core : Integrating properties to actions; adding tests
-rw-r--r--src/sugar/tutorius/actions.py17
-rw-r--r--src/sugar/tutorius/properties.py4
-rw-r--r--src/sugar/tutorius/tests/actiontests.py45
-rw-r--r--src/sugar/tutorius/tests/propertiestests.py6
-rwxr-xr-xsrc/sugar/tutorius/tests/run-tests.py5
5 files changed, 57 insertions, 20 deletions
diff --git a/src/sugar/tutorius/actions.py b/src/sugar/tutorius/actions.py
index b8c21e0..fc364e0 100644
--- a/src/sugar/tutorius/actions.py
+++ b/src/sugar/tutorius/actions.py
@@ -29,6 +29,7 @@ class Action(object):
"""Base class for Actions"""
def __init__(self):
object.__init__(self)
+ self.properties = {}
def do(self, **kwargs):
"""
@@ -43,12 +44,12 @@ class Action(object):
pass #Should raise NotImplemented?
def get_properties(self):
- if not hasattr(self, "_props") or self._props is None:
- self._props = []
+ if self.properties is None or len(self.properties) == 0:
+ self.properties = {}
for i in dir(self):
if isinstance(getattr(self,i), TutoriusProperty):
- self._props.append(i)
- return self._props
+ self.properties[i] = getattr(self,i)
+ return self.properties.keys()
class OnceWrapper(object):
"""
@@ -89,14 +90,12 @@ class DialogMessage(Action):
@param message A string to display to the user
@param pos A list of the form [x, y]
"""
- def __init__(self, message, pos=[0,0]):
+ def __init__(self, message, pos=None):
super(DialogMessage, self).__init__()
- self._message = message
- self._position = pos
self._dialog = None
- self.message = TStringProperty("")
- self.position = TArrayProperty([0,0], 2)
+ self.message = TStringProperty(message)
+ self.position = TArrayProperty(pos or [0, 0], 2, 2)
def do(self):
"""
diff --git a/src/sugar/tutorius/properties.py b/src/sugar/tutorius/properties.py
index cd12f90..a0bfa03 100644
--- a/src/sugar/tutorius/properties.py
+++ b/src/sugar/tutorius/properties.py
@@ -87,7 +87,7 @@ class TIntProperty(TutoriusProperty):
class TFloatProperty(TutoriusProperty):
"""
- Represents a floting point number. Can have an upper value limit and/or
+ Represents a floating point number. Can have an upper value limit and/or
a lower value limit.
"""
def __init__(self, value, lower_limit=None, upper_limit=None):
@@ -185,7 +185,7 @@ class TEnumProperty(TutoriusProperty):
class TBooleanProperty(TutoriusProperty):
"""
- Represents a True of False value.
+ Represents a True or False value.
"""
def __init__(self, value=False):
TutoriusProperty.__init__(self)
diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py
index cfb6114..6001ec7 100644
--- a/src/sugar/tutorius/tests/actiontests.py
+++ b/src/sugar/tutorius/tests/actiontests.py
@@ -27,9 +27,14 @@ import gtk
from sugar.tutorius.actions import *
from sugar.tutorius.services import ObjectStore
+test_props = {"prop_a":8, "prop_b":3, "prop_c":"Hi"}
+
class PropertyAction(Action):
def __init__(self, na):
- self.a = TIntProperty(na)
+ Action.__init__(self)
+ self.prop_a = TIntProperty(test_props["prop_a"])
+ self.prop_b = TIntProperty(test_props["prop_b"])
+ self.prop_c = TStringProperty(test_props["prop_c"])
def has_function(obj, function_name):
"""
@@ -40,13 +45,16 @@ def has_function(obj, function_name):
return False
class PropsTest(unittest.TestCase):
-
def test_get_properties(self):
- prop = PropertyAction(8)
+ act = PropertyAction(8)
+
+ assert act.get_properties() == test_props.keys(), "Action does not contain property 'a'"
+
+ for prop_name in act.get_properties():
+ assert act.properties[prop_name].value == test_props[prop_name], "Wrong initial value for property %s : %s"%(prop_name,str(act.properties[prop_name]))
- assert prop.get_properties() == ['a'], "Action does not contain property 'a'"
-class OnceWrapperTest(unittest.TestCase):
+class OnceWrapperTests(unittest.TestCase):
def validate_wrapper(self, wrapper_instance):
"""
Ensures that a given instance of a wrapper implements the Action
@@ -71,9 +79,34 @@ class OnceWrapperTest(unittest.TestCase):
onceWrap = OnceWrapper(prop)
self.validate_wrapper(onceWrap)
+
+ assert onceWrap.get_properties() == test_props.keys(), "OnceWrapper should give access to properties of the contained action"
+
+class DialogMessageTest(unittest.TestCase):
+ def setUp(self):
+ self.dial = DialogMessage("Message text", [200, 300])
+
+ def test_properties(self):
+ assert self.dial.message.value == "Message text", "Wrong start value for the message"
+
+ assert self.dial.position.value == [200, 300], "Wrong start value for the position"
+
+class BubbleMessageTest(unittest.TestCase):
+ def setUp(self):
+ self.bubble = BubbleMessage(message="Message text", pos=[200, 300], tailpos=[-15, -25])
+
+ def test_properties(self):
+ props = self.bubble.get_properties()
+
+ assert "message" in props, 'No message property of BubbleMessage'
+
+ assert "position" in props, 'No position property in BubbleMessage'
+
+ assert "tail_pos" in props, 'No tail position property in BubbleMessage'
+
class CountAction(Action):
- """
+ """
This action counts how many times it's do and undo methods get called
"""
def __init__(self):
diff --git a/src/sugar/tutorius/tests/propertiestests.py b/src/sugar/tutorius/tests/propertiestests.py
index b54f849..45ba264 100644
--- a/src/sugar/tutorius/tests/propertiestests.py
+++ b/src/sugar/tutorius/tests/propertiestests.py
@@ -294,6 +294,8 @@ class TBooleanPropertyTest(unittest.TestCase):
def test_basic_boolean(self):
assert self.prop.value == False, "Could not set initial value via constructor"
+ assert self.prop.type == "boolean", "Wrong type for TBooleanProperty : %s"%self.prop.type
+
self.prop.set(True)
assert self.prop.value == True, "Could not change the value via set"
@@ -321,6 +323,8 @@ class TEnumPropertyTest(unittest.TestCase):
def test_basic_enum(self):
assert self.prop.value == "hello", "Could not set initial value on property"
+ assert self.prop.type == "enum", "Wrong type for TEnumProperty : %s"%self.prop.type
+
self.prop.set(True)
assert self.prop.value, "Could not change the value via set"
@@ -341,6 +345,8 @@ class TFilePropertyTest(unittest.TestCase):
def test_basic_file(self):
assert self.prop.value == "propertiestests.py", "Could not set initial value"
+ assert self.prop.type == "file", "Wrong type for TFileProperty : %s"%self.prop.type
+
self.prop.set("run-tests.py")
assert self.prop.value == "run-tests.py", "Could not change value"
diff --git a/src/sugar/tutorius/tests/run-tests.py b/src/sugar/tutorius/tests/run-tests.py
index bf5a57e..87edd57 100755
--- a/src/sugar/tutorius/tests/run-tests.py
+++ b/src/sugar/tutorius/tests/run-tests.py
@@ -40,7 +40,6 @@ if __name__=='__main__':
import filterstests
import constraintstests
import propertiestests
-
suite = unittest.TestSuite()
suite.addTests(unittest.findTestCases(coretests))
suite.addTests(unittest.findTestCases(servicestests))
@@ -52,7 +51,6 @@ if __name__=='__main__':
suite.addTests(unittest.findTestCases(filterstests))
suite.addTests(unittest.findTestCases(constraintstests))
suite.addTests(unittest.findTestCases(propertiestests))
-
runner = unittest.TextTestRunner()
runner.run(suite)
@@ -69,7 +67,8 @@ if __name__=='__main__':
from linear_creatortests import *
from uamtests import *
from filterstests import *
- from constraintstests import *
+ from constraintstests import *
from propertiestests import *
+ from actiontests import *
unittest.main()