From 651700dfb6f42c61b8791b75f78cc60f7234ec92 Mon Sep 17 00:00:00 2001 From: Simon Poirier Date: Mon, 01 Jun 2009 07:15:56 +0000 Subject: refactoring propertiestests --- (limited to 'src/sugar/tutorius/tests') diff --git a/src/sugar/tutorius/tests/propertiestests.py b/src/sugar/tutorius/tests/propertiestests.py index 45ba264..d53ad38 100644 --- a/src/sugar/tutorius/tests/propertiestests.py +++ b/src/sugar/tutorius/tests/propertiestests.py @@ -20,56 +20,56 @@ from sugar.tutorius.constraints import * from sugar.tutorius.properties import * # Helper function to test the wrong types on a property, given its type -def try_wrong_values(prop): - if prop.type != "int": +def try_wrong_values(obj): + if type(obj).prop.type != "int": try: - prop.set(3) + obj.prop = 3 assert False, "Able to insert int value in property of type %s"%prop.type - except: + except ValueConstraint: pass - if prop.type != "float": + if type(obj).prop.type != "float": try: - prop.set(1.1) + obj.prop = 1.1 assert False, "Able to insert float value in property of type %s"%prop.type - except: + except ValueConstraint: pass - if prop.type != "string": + if type(obj).prop.type != "string": try: - prop.set("Fake string") + obj.prop = "Fake string" assert False, "Able to insert string value in property of type %s"%prop.type - except: + except ValueConstraint: pass - if prop.type != "array": + if type(obj).prop.type != "array": try: - prop.set([1, 2000, 3, 400]) + obj.prop = [1, 2000, 3, 400] assert False, "Able to insert array value in property of type %s"%prop.type - except: + except ValueConstraint: pass - if prop.type != "color": + if type(obj).prop.type != "color": try: - prop.set([1,2,3]) + obj.prop = [1,2,3] if prop.type != "array": assert False, "Able to insert color value in property of type %s"%prop.type - except: + except ValueConstraint: pass - if prop.type != "boolean": + if type(obj).prop.type != "boolean": try: - prop.set(True) + obj.prop = True if prop.type != "boolean": assert False, "Able to set boolean value in property of type %s"%prop.type - except: + except ValueConstraint: pass class BasePropertyTest(unittest.TestCase): def test_base_class(self): prop = TutoriusProperty() - assert prop.value == None, "There should not be an initial value in the base property" + assert prop.default == None, "There should not be an initial value in the base property" assert prop.type == None, "There should be no type associated with the base property" @@ -81,29 +81,35 @@ class BasePropertyTest(unittest.TestCase): class TIntPropertyTest(unittest.TestCase): def test_int_property(self): - prop = TIntProperty(22) + class klass(TPropContainer): + prop = TIntProperty(22) + obj = klass() - assert prop.value == 22, "Could not set value on property via constructor" + assert obj.prop == 22, "Could not set value on property via constructor" - assert prop.type == "int", "Wrong type on int property : %s" % prop.type - cons = prop.get_constraints() + assert klass.prop.type == "int", "Wrong type on int property : %s" % prop.type + cons = klass.prop.get_constraints() assert len(cons) == 2, "Not enough constraints on the int property" - prop.set(12) + obj.prop.set(12) - assert prop.value == 12, "Could not set value" + assert obj.prop.value == 12, "Could not set value" def test_wrong_values(self): - prop = TIntProperty(33) + class klass(TPropContainer): + prop = TIntProperty(33) + obj = klass() # Try setting values of other types try_wrong_values(prop) def test_limit_constructor(self): - prop = TIntProperty(22, 0, 30) + class klass(TPropContainer): + prop = TIntProperty(22, 0, 30) + obj = klass() try: - prop.set(-22) + obj.prop = -22 assert False, "Assigning an out-of-range value should trigger LowerLimitConstraint" except LowerLimitConstraintError: pass @@ -111,7 +117,7 @@ class TIntPropertyTest(unittest.TestCase): assert False, "Wrong exception triggered by assignation" try: - prop.set(222) + obj.prop = 222 assert False, "Assigning an out-of-range value should trigger UpperLimitConstraint" except UpperLimitConstraintError: pass @@ -134,6 +140,7 @@ class TIntPropertyTest(unittest.TestCase): pass except: assert False, "Wrong exception type on failed constructor" + def test_instance_assign(self): class TFloatPropertyTest(unittest.TestCase): def test_float_property(self): -- cgit v0.9.1