From d66690142b643401429bfff84d42acac002e1980 Mon Sep 17 00:00:00 2001 From: mike Date: Thu, 16 Apr 2009 18:54:50 +0000 Subject: LP 348570 Core : Integrating properties to actions; adding tests --- (limited to 'src/sugar/tutorius/tests') diff --git a/src/sugar/tutorius/tests/actiontests.py b/src/sugar/tutorius/tests/actiontests.py index ab9cdba..bce753e 100644 --- a/src/sugar/tutorius/tests/actiontests.py +++ b/src/sugar/tutorius/tests/actiontests.py @@ -27,24 +27,32 @@ 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 = na - - def set_a(self, na): - self._a = na - - def get_a(self): - return self._a - - a = property(fget=get_a, fset=set_a) - + 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): + """ + Checks whether the object has a function by that name. + """ + if hasattr(obj, function_name) and hasattr(obj.__getattribute__(function_name), "__call__"): + return True + 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 CountAction(Action): """ diff --git a/src/sugar/tutorius/tests/propertiestests.py b/src/sugar/tutorius/tests/propertiestests.py index 52a9a75..4f4caac 100644 --- a/src/sugar/tutorius/tests/propertiestests.py +++ b/src/sugar/tutorius/tests/propertiestests.py @@ -286,6 +286,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" @@ -313,6 +315,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" @@ -333,6 +337,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 63a8de1..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,5 +67,8 @@ if __name__=='__main__': from linear_creatortests import * from uamtests import * from filterstests import * + from constraintstests import * + from propertiestests import * + from actiontests import * unittest.main() -- cgit v0.9.1