File: test-time.py

package info (click to toggle)
pyxb 1.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 63,792 kB
  • ctags: 48,994
  • sloc: python: 235,928; sh: 803; xml: 657; makefile: 57
file content (75 lines) | stat: -rw-r--r-- 2,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
import logging
if __name__ == '__main__':
    logging.basicConfig()
_log = logging.getLogger(__name__)
import pyxb
import pyxb.binding.generate
import pyxb.utils.domutils

from xml.dom import Node

import os.path
schema_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../schemas/time.xsd'))
code = pyxb.binding.generate.GeneratePython(schema_location=schema_path)

rv = compile(code, 'test', 'exec')
eval(rv)

from pyxb.exceptions_ import *

def make_tTime (*args, **kw):
    for cls in [ tXMTime, tISO8601 ]:
        try:
            v = cls(*args, **kw)
            v.validateBinding()
            return v
        except Exception as e:
            pass
    return None
tTime._SetAlternativeConstructor(make_tTime)

import unittest

class TestTime (unittest.TestCase):
    KW_tISO8601 = { 'time' : '2009-06-03T13:43:00Z' }
    KW_tXMTime = { 'seconds' : 2, 'fractionalSeconds' : 0.3 }
    def testXMTime (self):
        t = tXMTime(seconds=1)
        self.assertEqual(1, t.seconds)
        self.assertEqual(None, t.fractionalSeconds)
        t = tXMTime(**self.KW_tXMTime)
        self.assertEqual(2, t.seconds)
        self.assertEqual(0.3, t.fractionalSeconds)
        t._setElement(time)
        xmls = t.toxml("utf-8")
        instance = CreateFromDocument(xmls)
        self.assertEqual(instance.seconds, t.seconds)
        self.assertEqual(instance.fractionalSeconds, t.fractionalSeconds)

    def testISO8601 (self):
        t = tISO8601(**self.KW_tISO8601)
        self.assertEqual((2009, 6, 3, 13, 43, 0, 2, 154, 0), t.time.timetuple())
        t._setElement(time)
        xmls = t.toxml("utf-8")
        instance = CreateFromDocument(xmls)
        self.assertEqual(instance.time.timetuple(), t.time.timetuple())

    def testAbstract (self):
        self.assertRaises(pyxb.AbstractInstantiationError, tTime, **self.KW_tXMTime)
        t = make_tTime(**self.KW_tXMTime)
        self.assertTrue(isinstance(t, tTime))
        self.assertTrue(isinstance(t, tXMTime))
        t = make_tTime(**self.KW_tISO8601)
        self.assertTrue(isinstance(t, tTime))
        self.assertTrue(isinstance(t, tISO8601))
        t = tTime.Factory(**self.KW_tXMTime)
        self.assertTrue(isinstance(t, tTime))
        self.assertTrue(isinstance(t, tXMTime))



if __name__ == '__main__':
    unittest.main()