Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/tests/propertiestests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/propertiestests.py')
-rw-r--r--tests/propertiestests.py94
1 files changed, 70 insertions, 24 deletions
diff --git a/tests/propertiestests.py b/tests/propertiestests.py
index 49d2312..55c3818 100644
--- a/tests/propertiestests.py
+++ b/tests/propertiestests.py
@@ -29,36 +29,35 @@ def try_wrong_values(obj):
try:
obj.prop = 3
assert False, "Able to insert int value in property of type %s"%typ
- except ValueError:
+ except TypeConstraintError:
pass
if typ != "float":
try:
obj.prop = 1.1
assert False, "Able to insert float value in property of type %s"%typ
- except ValueError:
+ except TypeConstraintError:
pass
- if typ != "string":
+ if typ != "string" and typ != "sequence":
try:
obj.prop = "Fake string"
assert False, "Able to insert string value in property of type %s"%typ
- except ValueError:
+ except TypeConstraintError:
pass
- if typ != "array":
+ if typ != "array" and typ != "color" and typ != "sequence":
try:
obj.prop = [1, 2000, 3, 400]
assert False, "Able to insert array value in property of type %s"%typ
- except ValueError:
+ except TypeConstraintError:
pass
- if typ != "color":
+ if typ != "color" and typ != "sequence" and typ != "array":
try:
obj.prop = [1,2,3]
- if typ != "array":
- assert False, "Able to insert color value in property of type %s"%typ
- except ValueError:
+ assert False, "Able to insert color value in property of type %s"%typ
+ except TypeConstraintError:
pass
if typ != "boolean":
@@ -66,7 +65,7 @@ def try_wrong_values(obj):
obj.prop = True
if typ != "boolean":
assert False, "Able to set boolean value in property of type %s"%typ
- except ValueError:
+ except TypeConstraintError:
pass
class BasePropertyTest(unittest.TestCase):
@@ -216,7 +215,7 @@ class TIntPropertyTest(unittest.TestCase):
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"
+ assert len(cons) == 3, "Not enough constraints on the int property"
obj.prop = 12
@@ -271,22 +270,22 @@ class TIntPropertyTest(unittest.TestCase):
class TFloatPropertyTest(unittest.TestCase):
def test_float_property(self):
class klass(TPropContainer):
- prop = TFloatProperty(22)
+ prop = TFloatProperty(22.0)
obj = klass()
- assert obj.prop == 22, "Could not set value on property via constructor"
+ assert obj.prop == 22.0, "Could not set value on property via constructor"
assert klass.prop.type == "float", "Wrong type on float property : %s" % klass.prop.type
cons = klass.prop.get_constraints()
- assert len(cons) == 2, "Not enough constraints on the float property"
+ assert len(cons) == 3, "Not enough constraints on the float property"
- obj.prop = 12
+ obj.prop = 12.0
- assert obj.prop == 12, "Could not set value"
+ assert obj.prop == 12.0, "Could not set value"
def test_wrong_values(self):
class klass(TPropContainer):
- prop = TFloatProperty(33)
+ prop = TFloatProperty(33.0)
obj = klass()
# Try setting values of other types
@@ -315,7 +314,7 @@ class TFloatPropertyTest(unittest.TestCase):
def test_failing_constructor(self):
try:
- prop = TFloatProperty(100, 0, 20)
+ prop = TFloatProperty(100.0, 0, 20)
assert False, "Creation of the property should fail."
except UpperLimitConstraintError:
pass
@@ -323,7 +322,7 @@ class TFloatPropertyTest(unittest.TestCase):
assert False, "Wrong exception type on failed constructor"
try:
- prop = TFloatProperty(-100, 0, 20)
+ prop = TFloatProperty(-100.0, 0, 20)
assert False, "Creation of the property should fail."
except LowerLimitConstraintError:
pass
@@ -419,6 +418,56 @@ class TArrayPropertyTest(unittest.TestCase):
except MinSizeConstraintError:
pass
+class TSequencePropertyTest(unittest.TestCase):
+ def test_basic_array(self):
+ class klass(TPropContainer):
+ prop = TSequenceProperty([1, 2, 3, 4])
+ obj = klass()
+
+ assert obj.prop == (1,2,3,4), "Unable to set initial value via constructor"
+
+ assert klass.prop.type == "sequence", "Wrong type for sequence : %s"%klass.prop.type
+
+ def test_wrong_values(self):
+ class klass(TPropContainer):
+ prop = TSequenceProperty([1,2,3,4,5])
+ obj = klass()
+
+ try_wrong_values(obj)
+
+ def test_size_limits(self):
+ class klass(TPropContainer):
+ prop = TSequenceProperty([1,2], None, 4)
+ obj = klass()
+
+ try:
+ obj.prop = [1,2,4,5,6,7]
+ assert False, "Maximum size limit constraint was not properly applied"
+ except MaxSizeConstraintError:
+ pass
+
+ class klass(TPropContainer):
+ prop = TSequenceProperty([1,2,3,4], 2)
+ obj = klass()
+
+ try:
+ obj.prop = [1]
+ assert False, "Minimum size limit constraint was not properly applied"
+ except MinSizeConstraintError:
+ pass
+
+ def test_failing_constructor(self):
+ try:
+ prop = TSequenceProperty([100, 0, 20], None, 2)
+ assert False, "Creation of the property should fail."
+ except MaxSizeConstraintError:
+ pass
+ try:
+ prop = TSequenceProperty([100, 0, 20], 4, None)
+ assert False, "Creation of the property should fail."
+ except MinSizeConstraintError:
+ pass
+
class TColorPropertyTest(unittest.TestCase):
def test_basic_color(self):
class klass(TPropContainer):
@@ -471,7 +520,7 @@ class TBooleanPropertyTest(unittest.TestCase):
try:
prop = TBooleanProperty(64)
assert False, "Creation of the property should fail with non-boolean value"
- except BooleanConstraintError:
+ except TypeConstraintError:
pass
except:
assert False, "Wrong exception type on failed constructor"
@@ -497,9 +546,6 @@ class TEnumPropertyTest(unittest.TestCase):
except EnumConstraintError:
pass
- def test_wrong_type(self):
- try_wrong_values(self.obj)
-
class TFilePropertyTest(unittest.TestCase):
root_folder = "/tmp/tutorius"