~ubuntu-branches/ubuntu/trusty/miro/trusty

« back to all changes in this revision

Viewing changes to portable/test/schematest.py

  • Committer: Daniel Hahler
  • Date: 2010-04-13 18:51:35 UTC
  • mfrom: (1.2.10 upstream)
  • Revision ID: ubuntu-launchpad@thequod.de-20100413185135-xi24v1diqg8w406x
Merging shared upstream rev into target branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
import unittest
6
6
 
7
7
from miro import schema
8
 
# much easier to type this way..
9
 
from miro.schema import SchemaString, SchemaInt, SchemaFloat, SchemaBool
10
 
from miro.schema import SchemaDateTime, SchemaList, SchemaDict, SchemaObject
11
 
from miro.schema import SchemaReprContainer, ValidationError
 
8
from miro.schema import (SchemaString, SchemaInt, SchemaFloat, SchemaBool,
 
9
                         SchemaDateTime, SchemaList, SchemaDict, SchemaObject,
 
10
                         SchemaReprContainer, ValidationError)
12
11
from miro.test.framework import MiroTestCase
13
12
 
14
13
class TestValidation(MiroTestCase):
15
 
    def testModuleVariablesDefined(self):
 
14
    def test_module_variables_defined(self):
16
15
        self.assert_(hasattr(schema, 'VERSION'))
17
16
        self.assert_(hasattr(schema, 'object_schemas'))
18
17
 
19
 
    def testNoneValidation(self):
 
18
    def test_none_validation(self):
20
19
        self.assertRaises(ValidationError, SchemaInt(noneOk=False).validate,
21
 
                None)
 
20
                          None)
22
21
        self.assertRaises(ValidationError, SchemaInt().validate, None)
23
22
        SchemaInt(noneOk=True).validate(None)
24
23
 
25
 
    def testBoolValiation(self):
 
24
    def test_bool_validation(self):
26
25
        schemabool = SchemaBool()
27
26
        self.assertRaises(ValidationError, schemabool.validate, 1)
28
27
        self.assertRaises(ValidationError, schemabool.validate, 0)
31
30
        schemabool.validate(True)
32
31
        schemabool.validate(False)
33
32
 
34
 
    def testDateTimeValiation(self):
 
33
    def test_date_time_validation(self):
35
34
        schemadatetime = SchemaDateTime()
36
35
        self.assertRaises(ValidationError, schemadatetime.validate, 1)
37
36
        self.assertRaises(ValidationError, schemadatetime.validate, 0)
39
38
        self.assertRaises(ValidationError, schemadatetime.validate, delta)
40
39
        schemadatetime.validate(datetime.datetime(1980, 8, 1))
41
40
 
42
 
    def testIntValiation(self):
 
41
    def test_int_validation(self):
43
42
        schemaint = SchemaInt()
44
43
        self.assertRaises(ValidationError, schemaint.validate, "One")
45
44
        self.assertRaises(ValidationError, schemaint.validate, 1.4)
46
45
        schemaint.validate(1)
47
46
        schemaint.validate(1L)
48
47
 
49
 
    def testFloatValiation(self):
 
48
    def test_float_validation(self):
50
49
        schemafloat = SchemaFloat()
51
50
        self.assertRaises(ValidationError, schemafloat.validate, "One half")
52
51
        self.assertRaises(ValidationError, schemafloat.validate, 1)
53
52
        schemafloat.validate(1.4)
54
53
 
55
 
    def testStringValidation(self):
 
54
    def test_string_validation(self):
56
55
        schemastring = SchemaString()
57
56
        self.assertRaises(ValidationError, schemastring.validate, 10123)
58
57
        self.assertRaises(ValidationError, schemastring.validate, "10123")
59
58
        schemastring.validate(u"10123")
60
59
 
61
 
    def testReprContainerValidation(self):
 
60
    def test_repr_container_validatoin(self):
62
61
        schemasimple = SchemaReprContainer()
63
62
        schemasimple.validate({1: u"Ben", u"pie": 3.1415})
64
63
        schemasimple.validate([1, 1, u"two", u"three", 5])
65
64
        schemasimple.validate({u'y2k': datetime.datetime(2000, 1, 1),
66
 
                'now': time.localtime()})
 
65
                               'now': time.localtime()})
67
66
        schemasimple.validate({
68
 
                'fib': (1, 1, u"two", u"three", 5),
69
 
                'square': (1, 4, u"nine", 16),
70
 
                'fact': (1, 2.0, 6, u"twenty-four"),
 
67
            'fib': (1, 1, u"two", u"three", 5),
 
68
            'square': (1, 4, u"nine", 16),
 
69
            'fact': (1, 2.0, 6, u"twenty-four"),
71
70
            })
72
 
        #make sure circular references doesn't screw it up
 
71
        # make sure circular references doesn't screw it up
73
72
        l = []
74
73
        d = {}
75
74
        l.extend([l, d])
80
79
        class TestObject(object):
81
80
            pass
82
81
        self.assertRaises(ValidationError, schemasimple.validate,
83
 
                TestObject())
 
82
                          TestObject())
84
83
        self.assertRaises(ValidationError, schemasimple.validate,
85
 
                [TestObject()])
 
84
                          [TestObject()])
86
85
        self.assertRaises(ValidationError, schemasimple.validate, 
87
 
                {'object': TestObject()})
 
86
                          {'object': TestObject()})
88
87
 
89
 
    def testListValidation(self):
 
88
    def test_list_validation(self):
90
89
        schemalist = SchemaList(SchemaInt())
91
90
        self.assertRaises(ValidationError, schemalist.validate,
92
 
                1234)
 
91
                          1234)
93
92
        schemalist.validate([1, 2, 3, 4])
94
93
 
95
 
    def testDictValidation(self):
 
94
    def test_dict_validation(self):
96
95
        schemadict = SchemaDict(SchemaInt(), SchemaString())
97
96
        self.assertRaises(ValidationError, schemadict.validate,
98
97
                1234)
99
98
        schemadict.validate({12: u"Buckle my shoe"})
100
99
 
101
 
    def testObjectValidation(self):
 
100
    def test_object_validation(self):
102
101
        class TestObject(object):
103
102
            pass
104
103
        class ChildObject(TestObject):