• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

contrib/opal/ZSI/test/test_list.py

00001 #!/usr/bin/env python
00002 import unittest, time, datetime
00003 import ZSI 
00004 from ZSI.writer import SoapWriter
00005 from ZSI import _get_element_nsuri_name
00006 from ZSI.schema import GED, TypeDefinition, ElementDeclaration
00007 from ZSI.parse import ParsedSoap
00008 from cStringIO import StringIO
00009 
00010 
00011 class TestList1_Def(ZSI.TC.List, TypeDefinition):
00012     itemType = (u'http://www.w3.org/2001/XMLSchema', u'dateTime')
00013     schema = "urn:test"
00014     type = (schema, "tUsage")
00015     def __init__(self, pname, **kw):
00016         ZSI.TC.List.__init__(self, pname, **kw)
00017 
00018 
00019 class TestList2_Def(ZSI.TC.List, TypeDefinition):
00020     itemType = ZSI.TC.gDateTime()
00021     schema = "urn:test"
00022     type = (schema, "tUsage")
00023     def __init__(self, pname, **kw):
00024         ZSI.TC.List.__init__(self, pname, **kw)
00025 
00026 
00027 class ListTestCase(unittest.TestCase):
00028     "test List TypeCode"
00029 
00030     def setUp(self):
00031         pass
00032 
00033     def tearDown(self):
00034         pass
00035 
00036     def check_list_defs(self):
00037         gl = globals()
00038         for klass in map(lambda h: gl[h], filter(lambda g: (g.startswith('TestList') and 
00039             issubclass(gl[g],ZSI.TC.List)), gl)):
00040 
00041             typecode = klass('whatever', nillable=True)
00042             data = None
00043             for i in range(10):
00044                 sw = SoapWriter()
00045                 sw.serialize(data, typecode)
00046                 s = str(sw)
00047                 print s
00048                 ps = ParsedSoap(s); pyobj = ps.Parse(typecode)
00049                 assert pyobj == data, 'Data corruption expected "%s", got "%s"' %(str(data),str(pyobj))
00050                 if data is None: 
00051                     data = []; continue;
00052 
00053                 # 
00054                 # cut last 3 fields off: weekday (0-6, Monday is 0), Julian day (day in the year, 1-366),
00055                 # DST (Daylight Savings Time) flag (-1, 0 or 1)
00056                 # 
00057                 utc = list(time.gmtime(i)[:-3]) + [999,0,0] 
00058                 data.append(tuple(utc))
00059 
00060 
00061 def makeTestSuite():
00062     suite = unittest.TestSuite()
00063     suite.addTest(unittest.makeSuite(ListTestCase, "check"))
00064     return suite
00065 
00066 def main():
00067     unittest.main(defaultTest="makeTestSuite")
00068 
00069 if __name__ == '__main__': 
00070     main()
00071 

Generated on Wed Oct 20 2010 11:12:16 for APBS by  doxygen 1.7.2