#!/usr/bin/env python ################################################################################ # # A bunch of regression type tests for the builder and parser. # ################################################################################ ident = '$Id: SOAPtest.py,v 1.19 2004/04/01 13:25:46 warnes Exp $' import urllib.request, urllib.parse, urllib.error import sys import unittest import re sys.path.insert(1, "..") from SOAPpy import * config=Config config.strict_range=1 # run these tests with this variable set both to 1 and 0 config.simplify_objects=0 # as borrowed from jake.soapware.org for float compares. def nearlyeq(a, b, prec = 1e-7): return abs(a - b) <= abs(a) * prec # helper def negfloat(x): return float(x) * -1.0 class Book(structType): def __init__(self): self.title = "Title of a book" structType.__init__(self) class Person(structType): def __init__(self): self.age = "49" self.height = "5.5" structType.__init__(self) class Result(structType): def __init__(self): structType.__init__(self, name = 'Result') self.Book = Book() self.Person = Person() class one: def __init__(self): self.str = "one" class two: def __init__(self): self.str = "two" class three: def __init__(self): self.str = "three" ws = ' \t\r\n' N = None class SOAPTestCase(unittest.TestCase): # big message def notestBigMessage(self): x=[] for y in string.lowercase: x.append(y*999999) buildSOAP(x) # test arrayType def testArrayType(self): x = structType( {"name":"widg1","quantity":200, "price":decimalType(45.99), "_typename":"LineItem"}) y = buildSOAP([x, x]) # could be parsed using an XML parser? self.assertTrue(string.find(y, "LineItem")>-1) # test arguments ordering def testOrdering(self): x = buildSOAP(method="newCustomer", namespace="urn:customer", \ kw={"name":"foo1", "address":"bar"}, \ config=SOAPConfig(argsOrdering={"newCustomer":("address", "name")})) # could be parsed using an XML parser? self.assertTrue(string.find(x, "
string.find(x, " My Life and Work Henry Ford 49 5.5 ''' # parse rules pr = {'SomeMethod': {'Result': {'Book': {'title':(NS.XSD, "string")}, 'Person': {'age':(NS.XSD, "int"), 'height':negfloat} } } } y = parseSOAPRPC(x, rules=pr) if config.simplify_objects: self.assertEqual(y['Result']['Person']['age'], 49); self.assertEqual(y['Result']['Person']['height'], -5.5); else: self.assertEqual(y.Result.Person.age, 49); self.assertEqual(y.Result.Person.height, -5.5); # Try the reverse def testStructOut(self): x = buildSOAP(Result()) def testIntFloat(self): x=''' West Virginia -546 -5.398 New Mexico -641 -9.351 Missouri -819 1.375 ''' y = parseSOAPRPC(x) if(config.simplify_objects): self.assertEqual(y['return'][0]['varString'], "West Virginia") self.assertEqual(y['return'][1]['varInt'], -641) self.assertEqual(y['return'][2]['varFloat'], 1.375) else: self.assertEqual(getattr(y,"return")[0].varString, "West Virginia") self.assertEqual(getattr(y,"return")[1].varInt, -641) self.assertEqual(getattr(y,"return")[2].varFloat, 1.375) def testArray1(self): x=''' West Virginia -546 -5.398 New Mexico -641 -9.351 Missouri -819 1.375 ''' y = parseSOAPRPC(x) if(config.simplify_objects): self.assertEqual(y["return"][0]['string'], "West Virginia") self.assertEqual(y["return"][1]['int'], -641) self.assertEqual(y["return"][2]['float'], 1.375) else: self.assertEqual(getattr(y,"return")[0].string, "West Virginia") self.assertEqual(getattr(y,"return")[1].int, -641) self.assertEqual(getattr(y,"return")[2].float, 1.375) def testUTF8Encoding1(self): x = ''' Hello \'<&>" ''' y = parseSOAPRPC(x) if config.simplify_objects: self.assertEqual(y['return2'][1], "Hello") else: self.assertEqual(y.return2[1], "Hello") def testUTF8Encoding2(self): x = ''' Hello \'<&>" Goodbye ''' y = parseSOAPRPC(x) self.assertEqual(type(y.a), type([])) self.assertEqual(type(y.b), type('')) self.assertEqual(type(y._getItemAsList('a')), type([])) self.assertEqual(type(y._getItemAsList('b')), type([])) self.assertEqual(y.b, 'Goodbye') self.assertEqual(y.a, ['', 'Hello', '\'<&>"']) self.assertEqual(y._getItemAsList('b'), ['Goodbye']) self.assertEqual(y._getItemAsList('c'), []) self.assertEqual(y._getItemAsList('c', 'hello'), 'hello') def testUTF8Encoding2(self): x = ''' Hello \'<&>" Goodbye ''' y = parseSOAP(x) self.assertEqual(y.a1, 'Hello') self.assertEqual(y.a3, 'Goodbye') self.assertFalse(hasattr(y, 'a2')) def testUTF8Encoding3(self): x = ''' My Life and Work Henry Ford
mailto:henryford@hotmail.com http://www.henryford.com
''' y = parseSOAPRPC(x) if config.simplify_objects: self.assertEqual(y['Result']['Book']['author']['name'], "Henry Ford") self.assertEqual(y['Result']['Book']['author']['address']['web'], "http://www.henryford.com") self.assertEqual(y['Result']['Book']['author']['address']['pers']['name'], "Henry Ford") else: self.assertEqual(y.Result.Book.author.name, "Henry Ford") self.assertEqual(y.Result.Book.author.address.web, "http://www.henryford.com") self.assertEqual(y.Result.Book.author.address.pers.name, "Henry Ford") # ref example def testRef(self): x = ''' 0 1 -1 3853.33325 ''' y = parseSOAPRPC(x) if config.simplify_objects: self.assertEqual(y['Return'][0], 0) self.assertEqual(y['Return'][1], 1) self.assertEqual(y['Return'][2], -1) self.assertTrue(nearlyeq(y['Return'][3], 3853.33325)) else: self.assertEqual(y.Return[0], 0) self.assertEqual(y.Return[1], 1) self.assertEqual(y.Return[2], -1) self.assertTrue(nearlyeq(y.Return[3], 3853.33325)) # Make sure passing in our own bodyType works. def testBodyType(self): a = [23, 42] b = bodyType() b.a = b.b = a x = buildSOAP(b) y = parseSOAP(x) self.assertEqual(id(y.a), id(y.b)) self.assertEqual(y.a, a) self.assertEqual(y.b, a) # Test Envelope versioning (see section 4.1.2 of http://www.w3.org/TR/SOAP). def testEnvelopeVersioning(self): xml = ''' <_1 xsi:type="xsd:int" SOAP-ENC:root="1">1 ''' try: parseSOAP(xml) except Exception as e: self.assertTrue(isinstance(e, faultType)) self.assertEqual(e.faultcode, '%s:VersionMismatch' % NS.ENV_T) self.assertFalse(hasattr(e, 'detail')) # Big terrible ordered data with attributes test. def testBigOrderedData(self): data = ''' first_main_item whatever etc. unoItem1 unoItem2 unoItem3 second_main_item whatever etc. dosItem1 dosItem2 dosItem3 single_main_item whatever etc. singleItem1 ''' x = parseSOAP(data) # print ".>",x.replyBlock.itemList._ns y = buildSOAP(x) def testEnvelope1(self): my_xml2 = ''' 5 34.5 10000 ''' (x,h) = parseSOAPRPC(my_xml2,header=1) def testEnvelope2(self): x =''' ''' x = parseSOAPRPC(x) def testEnvelope3(self): x = ''' hello ''' x, a = parseSOAPRPC(x, attrs = 1) if config.simplify_objects: self.assertEqual(a[id(x['Result'])][(None, 'name')], 'fred') else: self.assertEqual(a[id(x.Result)][(None, 'name')], 'fred') def testParseException(self): x=''' SOAP-ENV:Server Exception thrown on Server System.Runtime.Serialization.SerializationException, mscorlib, Version=1.0.2411.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Soap Parser Error System.Runtime.Serialization.SerializationException: Parse Error, xsd type not valid: Array at System.Runtime.Serialization.Formatters.Soap.SoapHandler.ProcessGetType(String value, String xmlKey) at System.Runtime.Serialization.Formatters.Soap.SoapHandler.ProcessType(ParseRecord pr, ParseRecord objectPr) at System.Runtime.Serialization.Formatters.Soap.SoapHandler.ProcessAttributes(ParseRecord pr, ParseRecord objectPr) at System.Runtime.Serialization.Formatters.Soap.SoapHandler.StartElement(String prefix, String name, String urn) at System.XML.XmlParser.ParseElement() at System.XML.XmlParser.ParseTag() at System.XML.XmlParser.Parse() at System.XML.XmlParser.Parse0() at System.XML.XmlParser.Run() at System.Runtime.Serialization.Formatters.Soap.SoapHandler.Error(IXmlProcessor p, Exception ex) at System.XML.XmlParser.Run() at System.Runtime.Serialization.Formatters.Soap.SoapParser.Run() at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser) at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler) at System.Runtime.Remoting.Channels.CoreChannel.DeserializeMessage(String mimeType, Stream xstm, Boolean methodRequest, IMessage msg, Header[] h) at System.Runtime.Remoting.Channels.SoapServerFormatterSink.ProcessMessage(IServerChannelSinkStack sinkStack, ITransportHeaders requestHeaders, Stream requestStream, IMessage& msg, ITransportHeaders& responseHeaders, Stream& responseStream) ''' z = parseSOAPRPC(x) self.assertEqual(z.__class__,faultType) self.assertEqual(z.faultstring, "Exception thrown on Server") def testFlatEnvelope(self): x = ''' ''' z = parseSOAPRPC(x) if config.simplify_objects: self.assertEqual(type(z['Result']), type('')) else: self.assertEqual(type(z.Result), type('')) def testNumericArray(self): x = [1,2,3,4,5] y = buildSOAP(x) z = parseSOAPRPC(y) self.assertEqual(x, z) def testStringArray(self): x = ["cayce", "asd", "buy"] y = buildSOAP(x) z = parseSOAPRPC(y) self.assertEqual(x, z) def testStringArray1(self): x = arrayType(['a', 'b', 'c']) y = buildSOAP(x) z = parseSOAP(y) if config.simplify_objects: self.assertEqual(z.v1._elemsname, 'item') self.assertEqual(z.v1, x) else: self.assertEqual(z['v1']['_elemsname'], 'item') self.assertEqual(z['v1'], x) def testStringArray2(self): x = arrayType(['d', 'e', 'f'], elemsname = 'elementals') y = buildSOAP(x) z = parseSOAP(y) if config.simplify_objects: self.assertEqual(z.v1._elemsname, 'elementals') self.assertEqual(z.v1, x) else: self.assertEqual(z['v1']['_elemsname'], 'elementals') self.assertEqual(z['v1'], x) def testInt1(self): my_xml = ''' 41 ''' s = parseSOAPRPC(my_xml) if config.simplify_objects: self.assertEqual(s['statenum'], 41) self.assertEqual(type(s['statenum']), type(0)) else: self.assertEqual(s.statenum, 41) self.assertEqual(type(s.statenum), type(0)) def testInt2(self): my_xml_ns = ''' 41 ''' s = parseSOAPRPC(my_xml_ns) if config.simplify_objects: self.assertEqual(s['statenum'], 41, "NS one failed") self.assertEqual(type(s['statenum']), type(0)) else: self.assertEqual(s.statenum, 41, "NS one failed") self.assertEqual(type(s.statenum), type(0)) def testPriceAndVolume(self): my_xml2 = ''' 5 34.5 10000 ''' s = parseSOAPRPC(my_xml2) if config.simplify_objects: self.assertEqual(s['PriceAndVolume']['LastTradePrice'].strip(), "34.5") self.assertEqual(s['PriceAndVolume']['DayVolume'].strip(), "10000") else: self.assertEqual(s.PriceAndVolume.LastTradePrice.strip(), "34.5") self.assertEqual(s.PriceAndVolume.DayVolume.strip(), "10000") def testInt3(self): my_xml3 = ''' 18 139 ''' s = parseSOAPRPC(my_xml3) if config.simplify_objects: self.assertEqual(s['param']['lowerBound'], 18) self.assertEqual(s['param']['upperBound'], 139) else: self.assertEqual(s.param.lowerBound, 18) self.assertEqual(s.param.upperBound, 139) def testBoolean(self): my_xml4 = ''' 12 Egypt 0 -31 7 ''' s = parseSOAPRPC(my_xml4) if config.simplify_objects: self.assertEqual(s['param'][0], 12) self.assertEqual(s['param'][1], "Egypt") self.assertEqual(s['param'][2], 0) self.assertEqual(s['param'][3], -31) self.assertEqual(s['param1'], None) self.assertEqual(s['param2'], None) self.assertEqual(s['param3'], 7) else: self.assertEqual(s.param[0], 12) self.assertEqual(s.param[1], "Egypt") self.assertEqual(s.param[2], 0) self.assertEqual(s.param[3], -31) self.assertEqual(s.param1, None) self.assertEqual(s.param2, None) self.assertEqual(s.param3, 7) def testFault(self): my_xml5 = ''' SOAP-ENV:Client Cant call getStateName because there are too many parameters. ''' s = parseSOAPRPC(my_xml5) self.assertEqual(s.__class__, faultType) self.assertEqual(s.faultcode, "SOAP-ENV:Client") def testArray2(self): my_xml6 = ''' 5 3 2 monkey cay hello 5 4 3 2 1 moose 5 ''' q = parseSOAPRPC(my_xml6) self.assertEqual(q[0], 5) self.assertEqual(q[1], 3) self.assertEqual(q[2], 2) self.assertEqual(q[3], 'monkey') self.assertEqual(q[4], 'cay') x = q[5] if config.simplify_objects: self.assertEqual(x['monkey'], 5) self.assertEqual(x['cat'], "hello") self.assertEqual(x['ferret'][0], 5) self.assertEqual(x['ferret'][3], 2) self.assertEqual(x['ferret'][5]['cow'], "moose") else: self.assertEqual(x.monkey, 5) self.assertEqual(x.cat, "hello") self.assertEqual(x.ferret[0], 5) self.assertEqual(x.ferret[3], 2) self.assertEqual(x.ferret[5].cow, "moose") def testArray3(self): x = arrayType([5,4,3,21], "spam") y = buildSOAP(x) z = parseSOAPRPC(y) self.assertEqual(x, z) # test struct def testStruct(self): x = structType(name = "eggs") x.test = 5 y = buildSOAP(x) z = parseSOAPRPC(y) if config.simplify_objects: self.assertEqual( x['test'], z['test'] ) else: self.assertEqual( x.test, z.test ) # test faults def testFault1(self): x = faultType("ServerError","Howdy",[5,4,3,2,1]) y = buildSOAP(x) z = parseSOAPRPC(y) self.assertEqual( x.faultcode , z.faultcode) self.assertEqual( x.faultstring , z.faultstring) self.assertEqual( x.detail , z.detail) # Test the recursion def testRecursion(self): o = one() t = two() o.t = t t.o = o tre = three() tre.o = o tre.t = t x = buildSOAP(tre) y = parseSOAPRPC(x) if config.simplify_objects: self.assertEqual( y['t']['o']['t']['o']['t']['o']['t']['str'] , "two") else: self.assertEqual( y.t.o.t.o.t.o.t.str , "two") # Test the recursion with structs def testRecursionWithStructs(self): o = structType("one") t = structType("two") o.t = t o.str = "one" t.o = o t.str = "two" tre = structType("three") tre.o = o tre.t = t tre.str = "three" x = buildSOAP(tre) y = parseSOAPRPC(x) if config.simplify_objects: self.assertEqual( y['t']['o']['t']['o']['t']['o']['t']['str'] , "two") else: self.assertEqual( y.t.o.t.o.t.o.t.str , "two") def testAmp(self): m = "Test Message & " x = structType("test") x.msg = m y = buildSOAP(x) z = parseSOAPRPC(y) if config.simplify_objects: self.assertEqual( m , z['msg']) else: self.assertEqual( m , z.msg) def testInt4(self): my_xml7 = ''' 18 139 ''' x = parseSOAPRPC(my_xml7) y = buildSOAP(x) # Does buildSOAP require a valid encoding? def testBuildSOAPEncoding(self): try: x = buildSOAP('hello', encoding = 'gleck') except LookupError as e: if str (e)[0:16] != 'unknown encoding': raise x = None except: print("Got unexpected exception: %s %s" % tuple (sys.exc_info ()[0:2])) x = '' self.assertEqual( x , None) # Does SOAPProxy require a valid encoding? def testSOAPProxyEncoding(self): try: x = SOAPProxy('', encoding = 'gleck') except LookupError as e: if str (e)[0:16] != 'unknown encoding': raise x = None except: print("Got unexpected exception: %s %s" % tuple (sys.exc_info ()[0:2])) x = '' self.assertEqual( x , None) # Does SOAPServer require a valid encoding? def testSOAPServerEncoding(self): try: x = SOAPServer(('localhost', 0), encoding = 'gleck') except LookupError as e: if str (e)[0:16] != 'unknown encoding': raise x = None except: print("Got unexpected exception: %s %s" % tuple (sys.exc_info ()[0:2])) x = '' self.assertEqual( x , None) def testEncodings(self): encodings = ('US-ASCII', 'ISO-8859-1', 'UTF-8', 'UTF-16') tests = ('A', '\u0041') for t in tests: for i in range (len (encodings)): x = buildSOAP (t, encoding = encodings[i]) y = parseSOAPRPC (x) self.assertEqual( y , t) tests = ('\u00a1',) for t in tests: for i in range (len (encodings)): try: x = buildSOAP (t, encoding = encodings[i]) except: if i > 0: raise continue y = parseSOAPRPC (x) self.assertEqual( y , t) tests = ('\u01a1', '\u2342') for t in tests: for i in range (len (encodings)): try: x = buildSOAP (t, encoding = encodings[i]) except: if i > 1: raise continue y = parseSOAPRPC (x) self.assertEqual( y , t) def build_xml(self, schema, type, value, attrs = ''): return ''' <_1 xsi:type="xsd:%(type)s"%(attrs)s>%(value)s ''' % {'schema': schema, 'type': type, 'value': value, 'attrs': attrs} # Make sure the various limits are checked when parsing def testIntegerLimits(self): for t, l in list(SOAPParser.intlimits.items()): try: parseSOAP(xml % (NS.XSD, t, 'hello')) raise AssertionError("parsed %s of 'hello' without error" % t) except AssertionError: raise except: pass if l[1] != None: try: parseSOAP(self.build_xml(NS.XSD, t, l[1] - 1)) raise AssertionError("parsed %s of %s without error" % \ (t, l[1] - 1)) except AssertionError: raise except UnderflowError: pass if l[2] != None: try: parseSOAP(self.build_xml(NS.XSD, t, l[2] + 1)) raise AssertionError("parsed %s of %s without error" % \ (t, l[2] + 1)) except AssertionError: raise except OverflowError: pass # Make sure the various limits are checked when parsing # Next, floats. Note that chances are good this won't work in any non-Unix Pythons. def testFloatLimits(self): for i in \ ( ('float', '-3.402823466391E+38'), ('float', '3.402823466391E+38'), ('float', '3.5e+38'), ('float', '6.9e-46'), ('double', '-1.7976931348623159E+308'), ('double', '1.7976931348623159E+308'), ('double', '1.8e308'), ('double', '2.4e-324'), ): try: parseSOAP(self.build_xml(NS.XSD, i[0], i[1])) # Hide this error for now, cause it is a bug in python 2.0 and 2.1 #if not (sys.version_info[0] == 2 and sys.version_info[1] <= 2) \ # and i[1]=='1.7976931348623159E+308': raise AssertionError("parsed %s of %s without error" % i) except AssertionError: raise except (UnderflowError, OverflowError): pass # Make sure we can't instantiate the base classes def testCannotInstantiateBaseClasses(self): for t in (anyType, NOTATIONType): try: x = t() raise AssertionError("instantiated %s directly" % repr(t)) except: pass # Try everything that requires initial data without any. def testMustBeInitialized(self): for t in (CDATAType, ENTITIESType, ENTITYType, IDType, IDREFType, IDREFSType, NCNameType, NMTOKENType, NMTOKENSType, NOTATIONType, NameType, QNameType, anyURIType, base64Type, base64BinaryType, binaryType, booleanType, byteType, decimalType, doubleType, durationType, floatType, hexBinaryType, intType, integerType, languageType, longType, negative_IntegerType, negativeIntegerType, non_Negative_IntegerType, non_Positive_IntegerType, nonNegativeIntegerType, nonPositiveIntegerType, normalizedStringType, positive_IntegerType, positiveIntegerType, shortType, stringType, timeDurationType, tokenType, unsignedByteType, unsignedIntType, unsignedLongType, unsignedShortType, untypedType, uriType, uriReferenceType): try: t() raise AssertionError("instantiated a %s with no value" % t.__name__) except AssertionError: raise except: pass def testInstantiations(self): # string, ENTITY, ID, IDREF, language, Name, NCName, # NMTOKEN, QName, untypedType for t in (stringType, ENTITYType, IDType, IDREFType, languageType, NameType, NCNameType, NMTOKENType, QNameType, untypedType): # First some things that shouldn't be taken as the current type test = (10, (), [], {}) for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad type (%s)" % \ (repr(t), repr(type(i)))) except AssertionError: raise except: pass # Now some things that should for i in ('hello', 'goodbye'): x = t(i) d = x._marshalData() if d != i: raise AssertionError("expected %s, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (i, z)) # ENTITIES, IDREFS, NMTOKENS for t in (ENTITIESType, IDREFSType, NMTOKENSType): # First some things that shouldn't be taken as the current type test = ({}, lambda x: x, ((),), ([],), [{}], [()]) for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad type (%s)" % \ repr(t)).with_traceback(repr(type(i))) except AssertionError: raise except: pass # Now some things that should for i in ('hello', (), [], ('hello', 'goodbye'), ['aloha', 'guten_tag']): x = t(i) d = x._marshalData() if type(i) in (type(()), type([])): j = list(i) else: j = [i] k = ' '.join(j) if d != k: raise AssertionError("expected %s, got %s" % (k, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != j: raise AssertionError("expected %s, got %s" % (repr(j), repr(z))) # uri, uriReference, anyURI for t in (uriType, uriReferenceType, anyURIType): # First some things that shouldn't be taken as the current type test = (10, (), [], {}) for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad type (%s)" % \ t.__name__).with_traceback(repr(type(i))) except AssertionError: raise except: pass # Now some things that should for i in ('hello', 'goodbye', '!@#$%^&*()-_=+[{]}\|;:\'",<.>/?`~'): x = t(i) d = x._marshalData() j = urllib.parse.quote(i) if d != j: raise AssertionError("expected %s, got %s" % (j, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # token First some things that shouldn't be valid because of type test = (42, 3.14, (), [], {}) t = tokenType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad type (%s)" % (t.__name__, repr(i))) except AssertionError: raise except AttributeError: pass # Now some things that shouldn't be valid because of content test = (' hello', 'hello ', 'hel\nlo', 'hel\tlo', 'hel lo', ' \n \t ') for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should be valid for i in ('', 'hello', 'hello'): x = t(i) d = x._marshalData() if d != i: raise AssertionError("expected %s, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i and i != '': raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) #### CDATA, normalizedString for t in (CDATAType, normalizedStringType): # First some things that shouldn't be valid because of type test = (42, 3.14, (), [], {}) for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad type (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except AttributeError: pass # Now some things that shouldn't be valid because of content test = ('hel\nlo', 'hel\rlo', 'hel\tlo', '\n\r\t') for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should be valid for i in ('', 'hello', 'hello', 'hel lo'): x = t(i) d = x._marshalData() if d != i: raise AssertionError("expected %s, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i and i != '': raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) #### boolean # First some things that shouldn't be valid test = (10, 'hello', (), [], {}) t = booleanType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % (t.__name__, repr(i))) except AssertionError: raise except: pass # Now some things that should for i in ((0, 'false'), ('false', 'false'), (1, 'true'), ('true', 'true'), (0.0, 'false'), (1.0, 'true')): x = t(i[0]) d = x._marshalData() if d != i[1]: raise AssertionError("%s: expected %s, got %s" % (i[0], i[1], d)) y = buildSOAP(x) z = parseSOAPRPC(y) j = ('false', 'true')[z] if j != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], repr(i[1]), repr(j))) # Now test parsing, both valid and invalid test = (('10', None), ('hello', None), ('false', 0), ('FALSE', 0), (ws + 'false' + ws, 0), (ws + '0' + ws, 0), ('0', 0), ('true', 1), ('TRUE', 1), ('1', 1), (ws + 'true' + ws, 1), (ws + '1' + ws, 1)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) # Can we give it a name and no type? #print x = t(1, name = 'George', typed = 0) #print "x=",x y = buildSOAP(x) #print "y=",y z = parseSOAP(y) #print "z=",z test = 'true' if z.George != test: raise AssertionError("expected %s, got %s" % (repr(test), repr(z))) # How about some attributes, set in various and sundry manners? x = t(1, attrs = {'nonamespaceURI': 1}) x._setAttrs({(None, 'NonenamespaceURI'): 2, ('http://some/namespace', 'namespaceURIattr1'): 3}) x._setAttr(('http://some/other/namespace', 'namespaceURIattr2'), 4) self.assertEqual( x._getAttr('nonamespaceURI') , 1) self.assertEqual( x._getAttr('NonenamespaceURI') , 2) self.assertEqual( x._getAttr(('http://some/namespace', 'namespaceURIattr1')) , 3) self.assertEqual( x._getAttr(('http://some/other/namespace', 'namespaceURIattr2')) , 4) self.assertEqual( x._getAttr('non-extant attr') , None) y = buildSOAP(x) z = parseSOAPRPC(y) self.assertEqual( z , 1) #### decimal # First some things that shouldn't be valid test = ('hello', (), [], {}) t = decimalType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad type (%s)" % \ (t.__name__, repr(type(i)))) except AssertionError: raise except: pass # Now some things that should for i in (10, 3.14, 23): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %f, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', None), ('1.2.3', None), ('10', 10), ('10.', 10), ('.1', .1), ('.1000000', .1), (ws + '10.4' + ws, 10.4)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) #### float # First some things that shouldn't be valid test = ('hello', (), [], {}, -3.402823466391E+38, 3.402823466391E+38) t = floatType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (10, 3.14, 23, -3.4028234663852886E+38, 3.4028234663852886E+38): x = t(i) d = x._marshalData() if not nearlyeq(float(d), i): raise AssertionError("expected %f, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if not nearlyeq(z, i): raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', None), ('1.2.3', None), ('10', 10), ('10.', 10), ('.1', .1), ('.1000000', .1), (ws + '10.4' + ws, 10.4), ('-3.402823466391E+38', None), ('3.402823466391E+38', None), ('-3.4028234663852886E+38', -3.4028234663852886E+38), ('3.4028234663852886E+38', 3.4028234663852886E+38)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if abs(z - i[1]) > 1e-6: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) #### double # First some things that shouldn't be valid test = ('hello', (), [], {}, -1.7976931348623159E+308, 1.7976931348623159E+308) t = doubleType for i in test: try: t(i) # Hide this error for now, cause it is a bug in python 2.0 and 2.1 if not (sys.version_info[0] == 2 and sys.version_info[1] <= 2 and i==1.7976931348623159E+308): raise AssertionError("instantiated a double with a bad value (%s)" % repr(i)) except AssertionError: raise except ValueError: pass # Now some things that should for i in (10, 3.14, 23, -1.79769313486E+308, 1.79769313486E+308): x = t(i) d = x._marshalData() if not nearlyeq(float(d), i): raise AssertionError("expected %s, got %s" % (i, str(x))) y = buildSOAP(x) z = parseSOAPRPC(y) if not nearlyeq(z, i): raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', None), ('1.2.3', None), ('10', 10), ('10.', 10), ('.1', .1), ('.1000000', .1), (ws + '10.4' + ws, 10.4), ('-1.7976931348623159E+308', None), ('1.7976931348623158E+308', None), ('-1.79769313486E+308', -1.79769313486E+308), ('1.79769313486E+308', 1.79769313486E+308)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if abs(z - i[1]) > 1e-6: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) #### hexBinary x = '' for i in range(256): x += chr(i) test = ('', x, 'hello') t = hexBinaryType l = [] for i in test: l.append(hexBinaryType(i)) x = buildSOAP(l) y = parseSOAPRPC(x) for i in range(len(test)): if test[i] != y[i]: raise AssertionError("@ %d expected '%s', got '%s'" % \ (i, test[i], y[i])) # Now test parsing, both valid and invalid test = (('hello', None), ('6163 747A65726F', None), ('6163747A65726', None), ('6163747A65726F', 'actzero'), (ws + '6163747A65726F' + ws, 'actzero')) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) #### base64Binary and base64 s = '' for i in range(256): s += chr(i) for t in (base64BinaryType, base64Type): # First some things that shouldn't be valid test = ((), [], {}, lambda x: x) for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except AttributeError: pass # Now some things that should test = ('', s, 'hello') l = [] for i in test: l.append(t(i)) x = buildSOAP(l) y = parseSOAPRPC(x) for i in range(len(test)): if test[i] != y[i]: raise AssertionError("@ %d expected '%s', got '%s'" % \ (i, test[i], y[i])) # Now test parsing, both valid and invalid test = (('hello', None), ('YWN0emVybw=', None), ('YWN 0emVybw==', 'actzero'), ('YWN0emVybw==', 'actzero'), (ws + 'YWN0emVybw==' + ws, 'actzero')) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) #### binary (uses s from above) # First some check invalid encodings try: x = binaryType('hello', encoding = 'yellow') raise AssertionError("created binary with invalid encoding") except AssertionError: raise except: pass for t in ('hex', 'base64'): # First some things that shouldn't be valid test = ((), [], {}, lambda x: x) for i in test: try: binaryType(i, encoding = t) raise AssertionError("instantiated a %s binary with a bad value (%s)" % \ (e, repr(i))) except AssertionError: raise except AttributeError: pass # Now some things that should test = ('', s, 'hello') l = [] for i in test: l.append(binaryType(i, encoding = t)) x = buildSOAP(l) y = parseSOAPRPC(x) for i in range(len(test)): if test[i] != y[i]: raise AssertionError("@ %d expected '%s', got '%s'" % \ (i, test[i], y[i])) # Now test parsing, both valid and invalid if t == 'hex': test = (('hello', None), ('6163 747A65726F', None), ('6163747A65726', None), ('6163747A65726F', 'actzero'), (ws + '6163747A65726F' + ws, 'actzero')) else: test = (('hello', None), ('YWN0emVybw=', None), ('YWN 0emVybw==', 'actzero'), ('YWN0emVybw==', 'actzero'), (ws + 'YWN0emVybw==' + ws, 'actzero')) for i in test: try: z = parseSOAPRPC(self.build_xml(NS.XSD, 'binary', i[0], ' encoding="%s"' % t)) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != None: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t, sys.exc_info()[0], sys.exc_info()[1])) # Finally try an Array of binaries (with references!) test = ('', s, 'hello') l = [] for i in test: l.append(binaryType(i, encoding = t)) l.append(l[1]) x = buildSOAP(l) y = parseSOAPRPC(x) for i in range(len(test)): if test[i] != y[i]: raise AssertionError("@ %d expected '%s', got '%s'" % \ (i, test[i], y[i])) # Make sure the references worked self.assertEqual( id(y[1]) , id(y[3])) def badTest(self, t, data): for i in data: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except: pass def goodTest(self, t, data): for i in data: x = t(i[0]) d = x._marshalData() if d != i[1]: raise AssertionError("%s(%s): expected %s, got %s" % \ (t.__name__, repr(i[0]), i[1], d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i[2]: raise AssertionError("%s(%s): expected %s, got %s" % \ (t.__name__, repr(i[0]), repr(i[2]), repr(z))) def parseTest(self, t, data): for i in data: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s(%s): expected %s, got %s" % \ (t.__name__, repr(i[0]), i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def allTests(self, t, baddata, gooddata, parsedata): self.badTest(t, baddata) self.goodTest(t, gooddata) self.parseTest(t, parsedata) # duration and timeDuration def testTimeDuration(self): baddata = \ ( 'hello', ('hello',), (-10, -10), (-10, 0, -10), (10.5, 10.5), (0, 10.5, 0, 10.5, 0), (1, 2, 3, 4, 5, 6, 7), (1, 2, 'hello', 4, 5, 6), (1, 2, 3.5, 4, 5, 6), ) gooddata = \ ( (0, 'PT0S', (N, N, N, N, N, 0.0,)), ((), 'PT0S', (N, N, N, N, N, 0.0,)), ([], 'PT0S', (N, N, N, N, N, 0.0,)), ((0.5,), 'PT0.5S', (N, N, N, N, N, 0.5,)), (10, 'PT10S', (N, N, N, N, N, 10.0,)), (-10, '-PT10S', (N, N, N, N, N, -10.0,)), (10.5, 'PT10.5S', (N, N, N, N, N, 10.5,)), ((10, 20), 'PT10M20S', (N, N, N, N, 10, 20.0)), ((-10, 20), '-PT10M20S', (N, N, N, N, -10, 20.0)), ((10, 0), 'PT10M', (N, N, N, N, 10, N)), ((10, 0, 0), 'PT10H', (N, N, N, 10, N, N)), ((10, 0, 0, 0), 'P10D', (N, N, 10, N, N, N)), ((10, 0, 0, 0, 0), 'P10M', (N, 10, N, N, N, N)), ((10, 0, 0, 0, 0, 0), 'P10Y', (10, N, N, N, N, N)), ((-10, 0, 0, 0, 0, 0), '-P10Y', (-10, N, N, N, N, N)), ((10, 0, 0, 0, 0, 20), 'P10YT20S', (10, N, N, N, N, 20.0,)), ((1, 2, 3, 4, 5, 6.75), 'P1Y2M3DT4H5M6.75S', (1, 2, 3, 4, 5, 6.75)), ((-1, 2, 3, 4, 5, 6.75), '-P1Y2M3DT4H5M6.75S', (-1, 2, 3, 4, 5, 6.75)), ((1, 2, 3, 10, 30, 0), 'P1Y2M3DT10H30M', (1, 2, 3, 10, 30, N)), ((1e6, 2e6, 3e6, 4e6, 5e6, 6.7e6), 'P1000000Y2000000M3000000DT4000000H5000000M6700000S', (1e6, 2e6, 3e6, 4e6, 5e6, 6.7e6)), ((1347, 0, N, 0, 0), 'P1347M', (N, 1347, N, N, N, N)), ((-1347, 0, 0, 0, N), '-P1347M', (N, -1347, N, N, N, N)), ((1e15, 0, 0, 0, 0), 'P1000000000000000M', (N, 1000000000000000, N, N, N, N)), ((-1e15, 0, 0, 0, 0), '-P1000000000000000M', (N, -1000000000000000, N, N, N, N)), ((1000000000000000, 0, 0, 0, 0), 'P1000000000000000M', (N, 1000000000000000, N, N, N, N)), ((-1000000000000000, 0, 0, 0, 0), '-P1000000000000000M', (N, -1000000000000000, N, N, N, N)), ) parsedata = ( ('hello', N), ('P T0S', N), ('P10.5Y10.5M', N), ('P1Y2MT', N), ('PT0S', (N, N, N, N, N, 0,)), ('P10Y', (10, N, N, N, N, N)), (ws + 'P10M' + ws, (N, 10, N, N, N, N)), ('P0Y1347M', (0, 1347, N, N, N, N)), ('P0Y1347M0D', (0, 1347, 0, N, N, N)), ('P0MT0M', (N, 0, N, N, 0, N)), ) for t in (durationType, timeDurationType): self.allTests(t, baddata, gooddata, parsedata) # dateTime, timeInstant, and timePeriod def testTimePeriod(self): baddata = \ ( 'hello', ('hello',), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 'hello'), (1, 2.5, 3, 4, 5, 6), (1, 0, 3, 4, 5, 6), (1, 13, 3, 4, 5, 6), (1, 1, 0, 4, 5, 6), (1, 1, 32, 4, 5, 6), (1, 2, 29, 4, 5, 6), (0, 2, 30, 4, 5, 6), (100, 2, 29, 4, 5, 6), (1, 2, 3, -1, 5, 6), (1, 2, 3, 24, 5, 6), (1, 2, 3, 4, -1, 6), (1, 2, 3, 4, 60, 6), (1, 2, 3, 4, 5, -1), (1, 2, 3, 4, 5, 61), (1, 3, 32, 4, 5, 6), (1, 4, 31, 4, 5, 6), (1, 5, 32, 4, 5, 6), (1, 6, 31, 4, 5, 6), (1, 7, 32, 4, 5, 6), (1, 8, 32, 4, 5, 6), (1, 9, 31, 4, 5, 6), (1, 10, 32, 4, 5, 6), (1, 11, 31, 4, 5, 6), (1, 12, 32, 4, 5, 6), ) gooddata = \ ( (1, '1970-01-01T00:00:01Z', (1970, 1, 1, 0, 0, 1.0)), (1.5, '1970-01-01T00:00:01.5Z', (1970, 1, 1, 0, 0, 1.5)), ((-1, 2, 3, 4, 5, 6), '-0001-02-03T04:05:06Z', (-1, 2, 3, 4, 5, 6.0)), ((1, 2, 3, 4, 5, 6), '0001-02-03T04:05:06Z', (1, 2, 3, 4, 5, 6.0)), ((10, 2, 3, 4, 5, 6), '0010-02-03T04:05:06Z', (10, 2, 3, 4, 5, 6.0)), ((100, 2, 3, 4, 5, 6), '0100-02-03T04:05:06Z', (100, 2, 3, 4, 5, 6.0)), ((1970, 2, 3, 4, 5, 6), '1970-02-03T04:05:06Z', (1970, 2, 3, 4, 5, 6.0)), ((-1970, 2, 3, 4, 5, 6), '-1970-02-03T04:05:06Z', (-1970, 2, 3, 4, 5, 6.0)), ((1970, 2.0, 3.0, 4, 5, 6.875), '1970-02-03T04:05:06.875Z', (1970, 2, 3, 4, 5, 6.875)), ((11990, 1, 2, 3, 4, 5.25, 0, 0, 0), '11990-01-02T03:04:05.25Z', (11990, 1, 2, 3, 4, 5.25)), ((1e15, 1, 2, 3, 4, 5.25, 0, 0, 0), '1000000000000000-01-02T03:04:05.25Z', (1e15, 1, 2, 3, 4, 5.25)), ((-1e15, 1, 2, 3, 4, 5.25, 0, 0, 0), '-1000000000000000-01-02T03:04:05.25Z', (-1e15, 1, 2, 3, 4, 5.25)), ((1000000000000000, 1, 2, 3, 4, 5.25, 0, 0, 0), '1000000000000000-01-02T03:04:05.25Z', (1e15, 1, 2, 3, 4, 5.25)), ((-1000000000000000, 1, 2, 3, 4, 5.25, 0, 0, 0), '-1000000000000000-01-02T03:04:05.25Z', (-1e15, 1, 2, 3, 4, 5.25)), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('1970 -01 -01T00:00:01Z', N), ('0001-02-03t07:08:23Z', N), # Invalid ranges ('2001-00-03T07:08:23Z', N), ('2001-13-03T07:08:23Z', N), ('2001-02-00T07:08:23Z', N), ('2001-02-29T07:08:23Z', N), ('2000-02-30T07:08:23Z', N), ('1900-02-29T07:08:23Z', N), ('2001-02-03T24:08:23Z', N), ('2001-02-03T04:60:23Z', N), ('2001-02-03T04:05:61Z', N), ('2001-01-32T04:05:06Z', N), ('2001-03-32T04:05:06Z', N), ('2001-04-31T04:05:06Z', N), ('2001-05-32T04:05:06Z', N), ('2001-06-31T04:05:06Z', N), ('2001-07-32T04:05:06Z', N), ('2001-08-32T04:05:06Z', N), ('2001-09-31T04:05:06Z', N), ('2001-10-32T04:05:06Z', N), ('2001-11-31T04:05:06Z', N), ('2001-12-32T04:05:06Z', N), # Whitespace (ws + '1970-01-01T00:00:00Z' + ws, (1970, 1, 1, 0, 0, 0)), # No timezones ('11971-02-03T04:05:06.125', (11971, 2, 3, 4, 5, 6.125)), ('1971-02-03T04:05:06.125', (1971, 2, 3, 4, 5, 6.125)), ('-1971-02-03T04:05:06.125', (-1971, 2, 3, 4, 5, 6.125)), # Non-zulu ('11971-02-03T04:05:06.125-07:08', (11971, 2, 3, 11, 13, 6.125)), ('11971-02-03T04:05:06.125+07:08', (11971, 2, 2, 20, 57, 6.125)), ('-11971-02-03T04:05:06.125-07:08', (-11971, 2, 3, 11, 13, 6.125)), ('-11971-02-03T04:05:06.125+07:08', (-11971, 2, 2, 20, 57, 6.125)), ('1971-02-03T04:05:06.125-07:08', (1971, 2, 3, 11, 13, 6.125)), ('1971-02-03T04:05:06.125+07:08', (1971, 2, 2, 20, 57, 6.125)), ('-1971-02-03T04:05:06.125-07:08', (-1971, 2, 3, 11, 13, 6.125)), ('-1971-02-03T04:05:06.125+07:08', (-1971, 2, 2, 20, 57, 6.125)), # Edgepoints (ranges) ('2001-01-03T07:08:09Z', (2001, 1, 3, 7, 8, 9)), ('2001-12-03T07:08:09Z', (2001, 12, 3, 7, 8, 9)), ('2001-02-01T07:08:09Z', (2001, 2, 1, 7, 8, 9)), ('2001-02-28T07:08:09Z', (2001, 2, 28, 7, 8, 9)), ('2000-02-29T07:08:09Z', (2000, 2, 29, 7, 8, 9)), ('1900-02-28T07:08:09Z', (1900, 2, 28, 7, 8, 9)), ('2001-02-03T00:08:09Z', (2001, 2, 3, 0, 8, 9)), ('2001-02-03T23:08:09Z', (2001, 2, 3, 23, 8, 9)), ('2001-02-03T04:00:09Z', (2001, 2, 3, 4, 0, 9)), ('2001-02-03T04:59:09Z', (2001, 2, 3, 4, 59, 9)), ('2001-02-03T04:05:00Z', (2001, 2, 3, 4, 5, 0)), ('2001-02-03T04:05:60.9Z', (2001, 2, 3, 4, 5, 60.9)), ('2001-01-31T04:05:06Z', (2001, 1, 31, 4, 5, 6)), ('2001-03-31T04:05:06Z', (2001, 3, 31, 4, 5, 6)), ('2001-04-30T04:05:06Z', (2001, 4, 30, 4, 5, 6)), ('2001-05-31T04:05:06Z', (2001, 5, 31, 4, 5, 6)), ('2001-06-30T04:05:06Z', (2001, 6, 30, 4, 5, 6)), ('2001-07-31T04:05:06Z', (2001, 7, 31, 4, 5, 6)), ('2001-08-31T04:05:06Z', (2001, 8, 31, 4, 5, 6)), ('2001-09-30T04:05:06Z', (2001, 9, 30, 4, 5, 6)), ('2001-10-31T04:05:06Z', (2001, 10, 31, 4, 5, 6)), ('2001-11-30T04:05:06Z', (2001, 11, 30, 4, 5, 6)), ('2001-12-31T04:05:06Z', (2001, 12, 31, 4, 5, 6)), # Edgepoints (crossing boundaries) ('0001-01-01T07:08:23+07:08', (1, 1, 1, 0, 0, 23)), ('0001-01-01T07:07:42+07:08', (0, 12, 31, 23, 59, 42)), ('-0004-01-01T07:07:42+07:08', (-5, 12, 31, 23, 59, 42)), ('2001-03-01T07:07:42+07:08', (2001, 2, 28, 23, 59, 42)), ('2000-03-01T07:07:42+07:08', (2000, 2, 29, 23, 59, 42)), ('1900-03-01T07:07:42+07:08', (1900, 2, 28, 23, 59, 42)), ) for t in (dateTimeType, timeInstantType, timePeriodType): self.allTests(t, baddata, gooddata, parsedata) # recurringInstant def testRecurringInstant(self): baddata = \ ( 'hello', ('hello',), (1, 2, N, 3, 4, 5), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 'hello'), (1, 2, 3.5, 4, 5, 6), ) gooddata = \ ( (1, '1970-01-01T00:00:01Z', (1970, 1, 1, 0, 0, 1.0)), (1.5, '1970-01-01T00:00:01.5Z', (1970, 1, 1, 0, 0, 1.5)), (1e9, '2001-09-09T01:46:40Z', (2001, 9, 9, 1, 46, 40.0)), ((1, 1, 2, 3, 4, 5), '-01-01-02T03:04:05Z', (1, 1, 2, 3, 4, 5)), ((-1, 1, 2, 3, 4, 5), '--01-01-02T03:04:05Z', (-1, 1, 2, 3, 4, 5)), ((10, 1, 2, 3, 4, 5), '-10-01-02T03:04:05Z', (10, 1, 2, 3, 4, 5)), ((-10, 1, 2, 3, 4, 5), '--10-01-02T03:04:05Z', (-10, 1, 2, 3, 4, 5)), ((100, 1, 2, 3, 4, 5), '0100-01-02T03:04:05Z', (100, 1, 2, 3, 4, 5)), ((-100, 1, 2, 3, 4, 5), '-0100-01-02T03:04:05Z', (-100, 1, 2, 3, 4, 5)), ((1970, 1, 2, 3, 4, 5), '1970-01-02T03:04:05Z', (1970, 1, 2, 3, 4, 5)), ((1970, 1, 2, 3, 4.0, 5.25), '1970-01-02T03:04:05.25Z', (1970, 1, 2, 3, 4, 5.25)), ((11990, 1, 2, 3, 4, 5.25), '11990-01-02T03:04:05.25Z', (11990, 1, 2, 3, 4, 5.25)), ((1e15, 1, 2, 3, 4, 5.25), '1000000000000000-01-02T03:04:05.25Z', (1e15, 1, 2, 3, 4, 5.25)), ((-1e15, 1, 2, 3, 4, 5.25), '-1000000000000000-01-02T03:04:05.25Z', (-1e15, 1, 2, 3, 4, 5.25)), ((N, 1, 2, 3, 4, 5.25), '---01-02T03:04:05.25Z', (N, 1, 2, 3, 4, 5.25)), ((N, N, 2, 3, 4, 5.25, 0, 0, 0), '-----02T03:04:05.25Z', (N, N, 2, 3, 4, 5.25)), ((N, N, -2, 3, 4, 5.25, 0, 0, 0), '------02T03:04:05.25Z', (N, N, -2, 3, 4, 5.25)), ((N, N, N, 3, 4, 5.25), '------T03:04:05.25Z', (N, N, N, 3, 4, 5.25)), ((N, N, N, N, 4, 5.25, 0, 0, 0), '------T-:04:05.25Z', (N, N, N, N, 4, 5.25)), ((N, N, N, N, N, 5.25), '------T-:-:05.25Z', (N, N, N, N, N, 5.25)), ((N, N, N, N, N, -5.25), '-------T-:-:05.25Z', (N, N, N, N, N, -5.25)), ((N, N, N, N, N, N, 0, 0, 0), '------T-:-:-Z', (N, N, N, N, N, N)), ((N, N, N, N, N, N, N), '------T-:-:-Z', (N, N, N, N, N, N)), ((N, N, N, N, N, N, N, N), '------T-:-:-Z', (N, N, N, N, N, N)), ((N, N, N, N, N, N, N, N, N), '------T-:-:-Z', (N, N, N, N, N, N)), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('1970 -01 -01T00:00:01Z', N), ('0001-01-01t07:08:23+07:08', N), # Invalid ranges ('2001-00-03T07:08:23Z', N), ('2001-13-03T07:08:23Z', N), ('2001-02-00T07:08:23Z', N), ('2001-02-29T07:08:23Z', N), ('2000-02-30T07:08:23Z', N), ('1900-02-29T07:08:23Z', N), ('2001-02-03T24:08:23Z', N), ('2001-02-03T04:60:23Z', N), ('2001-02-03T04:05:61Z', N), ('2001-01-32T04:05:06Z', N), ('2001-03-32T04:05:06Z', N), ('2001-04-31T04:05:06Z', N), ('2001-05-32T04:05:06Z', N), ('2001-06-31T04:05:06Z', N), ('2001-07-32T04:05:06Z', N), ('2001-08-32T04:05:06Z', N), ('2001-09-31T04:05:06Z', N), ('2001-10-32T04:05:06Z', N), ('2001-11-31T04:05:06Z', N), ('2001-12-32T04:05:06Z', N), # Whitespace (ws + '1970-01-01T00:00:01Z' + ws, (1970, 1, 1, 0, 0, 1)), # No timezones ('11971-02-03T04:05:06.125', (11971, 2, 3, 4, 5, 6.125)), ('-11971-02-03T04:05:06.125', (-11971, 2, 3, 4, 5, 6.125)), ('1971-02-03T04:05:06.125', (1971, 2, 3, 4, 5, 6.125)), ('-1971-02-03T04:05:06.125', (-1971, 2, 3, 4, 5, 6.125)), ('-71-02-03T04:05:06.125', (71, 2, 3, 4, 5, 6.125)), ('--71-02-03T04:05:06.125', (-71, 2, 3, 4, 5, 6.125)), ('---02-03T04:05:06.125', (N, 2, 3, 4, 5, 6.125)), ('----02-03T04:05:06.125', (N, -2, 3, 4, 5, 6.125)), ('-----03T04:05:06.125', (N, N, 3, 4, 5, 6.125)), ('------03T04:05:06.125', (N, N, -3, 4, 5, 6.125)), ('------T04:05:06.125', (N, N, N, 4, 5, 6.125)), ('-------T04:05:06.125', (N, N, N, -4, 5, 6.125)), ('------T-:05:06.125', (N, N, N, N, 5, 6.125)), ('-------T-:05:06.125', (N, N, N, N, -5, 6.125)), ('------T-:-:06.125', (N, N, N, N, N, 6.125)), ('-------T-:-:06.125', (N, N, N, N, N, -6.125)), ('------T-:-:-', (N, N, N, N, N, N)), ('-------T-:-:-', (N, N, N, N, N, N)), # Non-zulu ('11971-02-03T04:05:06.125-07:08', (11971, 2, 3, 11, 13, 6.125)), ('11971-02-03T04:05:06.125+07:08', (11971, 2, 2, 20, 57, 6.125)), ('-11971-02-03T04:05:06.125-07:08', (-11971, 2, 3, 11, 13, 6.125)), ('-11971-02-03T04:05:06.125+07:08', (-11971, 2, 2, 20, 57, 6.125)), ('1971-02-03T04:05:06.125-07:08', (1971, 2, 3, 11, 13, 6.125)), ('1971-02-03T04:05:06.125+07:08', (1971, 2, 2, 20, 57, 6.125)), ('-1971-02-03T04:05:06.125-07:08', (-1971, 2, 3, 11, 13, 6.125)), ('-1971-02-03T04:05:06.125+07:08', (-1971, 2, 2, 20, 57, 6.125)), ('-71-02-03T04:05:06.125-07:08', (71, 2, 3, 11, 13, 6.125)), ('-71-02-03T04:05:06.125+07:08', (71, 2, 2, 20, 57, 6.125)), ('--71-02-03T04:05:06.125-07:08', (-71, 2, 3, 11, 13, 6.125)), ('--71-02-03T04:05:06.125+07:08', (-71, 2, 2, 20, 57, 6.125)), ('---02-03T04:05:06.125-07:08', (N, 2, 3, 11, 13, 6.125)), ('---02-03T04:05:06.125+07:08', (N, 2, 2, 20, 57, 6.125)), ('----02-03T04:05:06.125-07:08', (N, -2, 3, 11, 13, 6.125)), ('----02-03T04:05:06.125+07:08', (N, -2, 2, 20, 57, 6.125)), ('-----03T04:05:06.125-07:08', (N, N, 3, 11, 13, 6.125)), ('-----03T04:05:06.125+07:08', (N, N, 2, 20, 57, 6.125)), ('------03T04:05:06.125-07:08', (N, N, -3, 11, 13, 6.125)), ('------03T04:05:06.125+07:08', (N, N, -4, 20, 57, 6.125)), ('------T04:05:06.125-07:08', (N, N, N, 11, 13, 6.125)), ('------T04:05:06.125+07:08', (N, N, N, -4, 57, 6.125)), ('-------T04:05:06.125-07:08', (N, N, N, 3, 13, 6.125)), ('-------T04:05:06.125+07:08', (N, N, N, -12, 57, 6.125)), ('------T-:05:06.125-07:08', (N, N, N, N, 433, 6.125)), ('------T-:05:06.125+07:08', (N, N, N, N, -423, 6.125)), ('-------T-:05:06.125-07:08', (N, N, N, N, 423, 6.125)), ('-------T-:05:06.125+07:08', (N, N, N, N, -433, 6.125)), ('------T-:-:06.125-07:08', (N, N, N, N, 428, 6.125)), ('------T-:-:06.125+07:08', (N, N, N, N, -428, 6.125)), ('-------T-:-:06.125-07:08', (N, N, N, N, 427, 53.875)), ('-------T-:-:06.125+07:08', (N, N, N, N, -429, 53.875)), ('------T-:-:--07:08', (N, N, N, N, 428, 0)), ('------T-:-:-+07:08', (N, N, N, N, -428, 0)), ('-------T-:-:--07:08', (N, N, N, N, 428, 0)), ('-------T-:-:-+07:08', (N, N, N, N, -428, 0)), # Edgepoints (ranges) ('2001-01-03T07:08:09Z', (2001, 1, 3, 7, 8, 9)), ('2001-12-03T07:08:09Z', (2001, 12, 3, 7, 8, 9)), ('2001-02-01T07:08:09Z', (2001, 2, 1, 7, 8, 9)), ('2001-02-28T07:08:09Z', (2001, 2, 28, 7, 8, 9)), ('2000-02-29T07:08:09Z', (2000, 2, 29, 7, 8, 9)), ('1900-02-28T07:08:09Z', (1900, 2, 28, 7, 8, 9)), ('2001-02-03T00:08:09Z', (2001, 2, 3, 0, 8, 9)), ('2001-02-03T23:08:09Z', (2001, 2, 3, 23, 8, 9)), ('2001-02-03T04:00:09Z', (2001, 2, 3, 4, 0, 9)), ('2001-02-03T04:59:09Z', (2001, 2, 3, 4, 59, 9)), ('2001-02-03T04:05:00Z', (2001, 2, 3, 4, 5, 0)), ('2001-02-03T04:05:60.9Z', (2001, 2, 3, 4, 5, 60.9)), ('2001-01-31T04:05:06Z', (2001, 1, 31, 4, 5, 6)), ('2001-03-31T04:05:06Z', (2001, 3, 31, 4, 5, 6)), ('2001-04-30T04:05:06Z', (2001, 4, 30, 4, 5, 6)), ('2001-05-31T04:05:06Z', (2001, 5, 31, 4, 5, 6)), ('2001-06-30T04:05:06Z', (2001, 6, 30, 4, 5, 6)), ('2001-07-31T04:05:06Z', (2001, 7, 31, 4, 5, 6)), ('2001-08-31T04:05:06Z', (2001, 8, 31, 4, 5, 6)), ('2001-09-30T04:05:06Z', (2001, 9, 30, 4, 5, 6)), ('2001-10-31T04:05:06Z', (2001, 10, 31, 4, 5, 6)), ('2001-11-30T04:05:06Z', (2001, 11, 30, 4, 5, 6)), ('2001-12-31T04:05:06Z', (2001, 12, 31, 4, 5, 6)), # Edgepoints (crossing boundaries) ('0001-01-01T07:08:23+07:08', (1, 1, 1, 0, 0, 23)), ('0001-01-01T07:07:42+07:08', (0, 12, 31, 23, 59, 42)), ('-0004-01-01T07:07:42+07:08', (-5, 12, 31, 23, 59, 42)), ('2001-03-01T07:07:42+07:08', (2001, 2, 28, 23, 59, 42)), ('2000-03-01T07:07:42+07:08', (2000, 2, 29, 23, 59, 42)), ('1900-03-01T07:07:42+07:08', (1900, 2, 28, 23, 59, 42)), ('---03-01T07:07:42+07:08', (N, 2, 28, 23, 59, 42)), ) for t in (recurringInstantType,): self.allTests(t, baddata, gooddata, parsedata) def testTime(self): baddata = \ ( 'hello', ('hello',), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5, 6, 7, 8), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 'hello'), (1, 2.5, 3), (25, 0, 0), (1, 60, 0), (1, 0, 61), ) gooddata = \ ( (1, '00:00:01Z', (0, 0, 1.0)), (1.5, '00:00:01.5Z', (0, 0, 1.5)), (3661.5, '01:01:01.5Z', (1, 1, 1.5)), (86399.75, '23:59:59.75Z', (23, 59, 59.75)), ((1,), '01:00:00Z', (1, 0, 0)), ((1, 2), '01:02:00Z', (1, 2, 0)), ((10, 20.0, 30), '10:20:30Z', (10, 20, 30.0)), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('00 00:01Z', N), ('07:O8:23Z', N), # Invalid ranges ('24:08:23Z', N), ('04:60:23Z', N), ('04:05:61Z', N), # Whitespace (ws + '00:00:01Z' + ws, (0, 0, 1)), # No timezones ('04:05:06.125', (4, 5, 6.125)), # Non-zulu ('04:05:06.125-07:08', (11, 13, 6.125)), ('04:05:06.125+07:08', (-4, 57, 6.125)), # Edgepoints (ranges) ('00:08:09Z', (0, 8, 9)), ('23:08:09Z', (23, 8, 9)), ('04:00:09Z', (4, 0, 9)), ('04:59:09Z', (4, 59, 9)), ('04:05:00Z', (4, 5, 0)), ('04:05:60.9Z', (4, 5, 60.9)), # Edgepoints (crossing boundaries) ('07:08:23+07:08', (0, 0, 23)), ('07:07:42+07:08', (-1, 59, 42)), ) for t in (timeType,): self.allTests(t, baddata, gooddata, parsedata) def testDate(self): baddata = \ ( 'hello', ('hello',), (1, 2, 3, 4, 5), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3, 4, 5, 'hello'), (1, 2.5, 3, 4, 5, 6), (1, 2, 3.5), (1, 0, 3), (1, 13, 3), (1, 1, 0), (1, 1, 32), (1, 2, 29), (0, 2, 30), (100, 2, 29), (1, 3, 32), (1, 4, 31), (1, 5, 32), (1, 6, 31), (1, 7, 32), (1, 8, 32), (1, 9, 31), (1, 10, 32), (1, 11, 31), (1, 12, 32), ) gooddata = \ ( (1, '1970-01-01Z', (1970, 1, 1)), (1.5, '1970-01-01Z', (1970, 1, 1)), ((2,), '0002-01-01Z', (2, 1, 1)), ((2, 3), '0002-03-01Z', (2, 3, 1)), ((-2, 3, 4), '-0002-03-04Z', (-2, 3, 4)), ((2, 3, 4), '0002-03-04Z', (2, 3, 4)), ((10, 2, 3), '0010-02-03Z', (10, 2, 3)), ((100, 2, 3), '0100-02-03Z', (100, 2, 3)), ((1970, 2, 3), '1970-02-03Z', (1970, 2, 3)), ((-1970, 2, 3), '-1970-02-03Z', (-1970, 2, 3)), ((1970, 2.0, 3.0), '1970-02-03Z', (1970, 2, 3)), ((11990, 1, 2), '11990-01-02Z', (11990, 1, 2)), ((1e15, 1, 2), '1000000000000000-01-02Z', (1e15, 1, 2)), ((-1e15, 1, 2), '-1000000000000000-01-02Z', (-1e15, 1, 2)), ((1000000000000000, 1, 2), '1000000000000000-01-02Z', (1e15, 1, 2)), ((-1000000000000000, 1, 2), '-1000000000000000-01-02Z', (-1e15, 1, 2)), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('1970 -01 -01Z', N), ('0001-02-03z', N), # Invalid ranges ('2001-00-03Z', N), ('2001-13-03Z', N), ('2001-02-00Z', N), ('2001-02-29Z', N), ('2000-02-30Z', N), ('1900-02-29Z', N), ('2001-01-32Z', N), ('2001-03-32Z', N), ('2001-04-31Z', N), ('2001-05-32Z', N), ('2001-06-31Z', N), ('2001-07-32Z', N), ('2001-08-32Z', N), ('2001-09-31Z', N), ('2001-10-32Z', N), ('2001-11-31Z', N), ('2001-12-32Z', N), # Whitespace (ws + '1970-01-01Z' + ws, (1970, 1, 1)), # No timezones ('11971-02-03', (11971, 2, 3)), ('1971-02-03', (1971, 2, 3)), ('-1971-02-03', (-1971, 2, 3)), # Non-zulu ('11971-02-03-07:08', (11971, 2, 3)), ('11971-02-03+07:08', (11971, 2, 2)), ('-11971-02-03-07:08', (-11971, 2, 3)), ('-11971-02-03+07:08', (-11971, 2, 2)), ('1971-02-03-07:08', (1971, 2, 3)), ('1971-02-03+07:08', (1971, 2, 2)), ('-1971-02-03-07:08', (-1971, 2, 3)), ('-1971-02-03+07:08', (-1971, 2, 2)), # Edgepoints (ranges) ('2001-01-03Z', (2001, 1, 3)), ('2001-12-03Z', (2001, 12, 3)), ('2001-02-01Z', (2001, 2, 1)), ('2001-02-28Z', (2001, 2, 28)), ('2000-02-29Z', (2000, 2, 29)), ('1900-02-28Z', (1900, 2, 28)), ('2001-01-31Z', (2001, 1, 31)), ('2001-03-31Z', (2001, 3, 31)), ('2001-04-30Z', (2001, 4, 30)), ('2001-05-31Z', (2001, 5, 31)), ('2001-06-30Z', (2001, 6, 30)), ('2001-07-31Z', (2001, 7, 31)), ('2001-08-31Z', (2001, 8, 31)), ('2001-09-30Z', (2001, 9, 30)), ('2001-10-31Z', (2001, 10, 31)), ('2001-11-30Z', (2001, 11, 30)), ('2001-12-31Z', (2001, 12, 31)), # Edgepoints (crossing boundaries) ('0001-01-01+07:08', (0, 12, 31)), ('-0004-01-01+07:08', (-5, 12, 31)), ('2001-03-01+07:08', (2001, 2, 28)), ('2000-03-01+07:08', (2000, 2, 29)), ('1900-03-01+07:08', (1900, 2, 28)), ) for t in (dateType,): self.allTests(t, baddata, gooddata, parsedata) def testGYearMonth(self): baddata = \ ( 'hello', ('hello',), (1, 2, 3), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (1, 2, 3.5), (1, 'hello'), (1, 2.5), (1, 0), (1, 13), ) gooddata = \ ( (1, '1970-01Z', (1970, 1)), (1.5, '1970-01Z', (1970, 1)), ((2,), '0002-01Z', (2, 1)), ((2, 3), '0002-03Z', (2, 3)), ((-2, 3), '-0002-03Z', (-2, 3)), ((10, 2), '0010-02Z', (10, 2)), ((100, 2), '0100-02Z', (100, 2)), ((1970, 2), '1970-02Z', (1970, 2)), ((-1970, 2), '-1970-02Z', (-1970, 2)), ((1970, 2.0), '1970-02Z', (1970, 2)), ((11990, 1), '11990-01Z', (11990, 1)), ((1e15, 1), '1000000000000000-01Z', (1e15, 1)), ((-1e15, 1), '-1000000000000000-01Z', (-1e15, 1)), ((1000000000000000, 1), '1000000000000000-01Z', (1e15, 1)), ((-1000000000000000, 1), '-1000000000000000-01Z', (-1e15, 1)), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('1970 -01Z', N), ('0001-02z', N), # Invalid ranges ('2001-00Z', N), ('2001-13Z', N), # Whitespace (ws + '1970-01Z' + ws, (1970, 1)), # No timezones ('11971-02', (11971, 2)), ('1971-02', (1971, 2)), ('-1971-02', (-1971, 2)), # Non-zulu ('11971-02-07:08', (11971, 2)), ('11971-02+07:08', (11971, 1)), ('-11971-02-07:08', (-11971, 2)), ('-11971-02+07:08', (-11971, 1)), ('1971-02-07:08', (1971, 2)), ('1971-02+07:08', (1971, 1)), ('-1971-02-07:08', (-1971, 2)), ('-1971-02+07:08', (-1971, 1)), # Edgepoints (ranges) ('2001-01Z', (2001, 1)), ('2001-12Z', (2001, 12)), # Edgepoints (crossing boundaries) ('0001-01+07:08', (0, 12)), ('-0004-01+07:08', (-5, 12)), ('2001-03+07:08', (2001, 2)), ('2000-03+07:08', (2000, 2)), ('1900-03+07:08', (1900, 2)), ) for t in (gYearMonthType,): self.allTests(t, baddata, gooddata, parsedata) def testGYearAndYear(self): baddata = \ ( 'hello', ('hello',), (1, 2), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (2.5,), ) gooddata = \ ( (1, '0001Z', 1), (10, '0010Z', 10), (100, '0100Z', 100), (1970, '1970Z', 1970), (-1970, '-1970Z', -1970), (1970, '1970Z', 1970), (11990.0, '11990Z', 11990), (1e15, '1000000000000000Z', 1e15), (-1e15, '-1000000000000000Z', -1e15), (1000000000000000, '1000000000000000Z', 1e15), (-1000000000000000, '-1000000000000000Z', -1e15), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('197OZ', N), ('0001z', N), # Whitespace (ws + '1970Z' + ws, 1970), # No timezones ('11971', 11971), ('1971', 1971), ('-1971', -1971), # Non-zulu ('11971-07:08', 11971), ('11971+07:08', 11970), ('-11971-07:08', -11971), ('-11971+07:08', -11972), ('1971-07:08', 1971), ('1971+07:08', 1970), ('-1971-07:08', -1971), ('-1971+07:08', -1972), # Edgepoints (crossing boundaries) ('0001+07:08', 0), ('-0004+07:08', -5), ) for t in (gYearType, yearType): self.allTests(t, baddata, gooddata, parsedata) def testCentury(self): baddata = \ ( 'hello', ('hello',), (1, 2), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (2.5,), ) gooddata = \ ( (1, '01Z', 1), (10, '10Z', 10), (100, '100Z', 100), (19, '19Z', 19), (-19, '-19Z', -19), (19, '19Z', 19), (119.0, '119Z', 119), (1e15, '1000000000000000Z', 1e15), (-1e15, '-1000000000000000Z', -1e15), (1000000000000000, '1000000000000000Z', 1e15), (-1000000000000000, '-1000000000000000Z', -1e15), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('197OZ', N), ('0001z', N), # Whitespace (ws + '1970Z' + ws, 1970), # No timezones ('11971', 11971), ('1971', 1971), ('-1971', -1971), # Non-zulu ('11971-07:08', 11971), ('11971+07:08', 11970), ('-11971-07:08', -11971), ('-11971+07:08', -11972), ('1971-07:08', 1971), ('1971+07:08', 1970), ('-1971-07:08', -1971), ('-1971+07:08', -1972), # Edgepoints (crossing boundaries) ('0001+07:08', 0), ('-0004+07:08', -5), ) for t in (centuryType,): self.allTests(t, baddata, gooddata, parsedata) def testGMonthDayAndRecurringDate(self): baddata = \ ( 'hello', ('hello',), (3, 4, 5), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (4, 5, 'hello'), (2.5, 3), (0, 3), (13, 3), (1, 0), (1, 32), (2, 29), (3, 32), (4, 31), (5, 32), (6, 31), (7, 32), (8, 32), (9, 31), (10, 32), (11, 31), (12, 32), ) gooddata = \ ( (1, '--01-01Z', (1, 1)), (1.5, '--01-01Z', (1, 1)), ((2,), '--02-01Z', (2, 1)), ((2, 3), '--02-03Z', (2, 3)), ((10, 2), '--10-02Z', (10, 2)), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('--01 -01Z', N), ('--02-03z', N), # Invalid ranges ('--00-03Z', N), ('--13-03Z', N), ('--01-32Z', N), ('--02-00Z', N), ('--02-29Z', N), ('--03-32Z', N), ('--04-31Z', N), ('--05-32Z', N), ('--06-31Z', N), ('--07-32Z', N), ('--08-32Z', N), ('--09-31Z', N), ('--10-32Z', N), ('--11-31Z', N), ('--12-32Z', N), # Whitespace (ws + '--01-01Z' + ws, (1, 1)), # No timezones ('--02-03', (2, 3)), # Non-zulu ('--02-03-07:08', (2, 3)), ('--02-03+07:08', (2, 2)), # Edgepoints (ranges) ('--01-03Z', (1, 3)), ('--12-03Z', (12, 3)), ('--01-31Z', (1, 31)), ('--02-01Z', (2, 1)), ('--02-28Z', (2, 28)), ('--03-31Z', (3, 31)), ('--04-30Z', (4, 30)), ('--05-31Z', (5, 31)), ('--06-30Z', (6, 30)), ('--07-31Z', (7, 31)), ('--08-31Z', (8, 31)), ('--09-30Z', (9, 30)), ('--10-31Z', (10, 31)), ('--11-30Z', (11, 30)), ('--12-31Z', (12, 31)), # Edgepoints (crossing boundaries) ('--01-01+07:08', (12, 31)), ('--03-01+07:08', (2, 28)), ) for t in (gMonthDayType, recurringDateType): self.allTests(t, baddata, gooddata, parsedata) def testGMonthAndMonth(self): baddata = \ ( 'hello', ('hello',), (3, 4,), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (2.5,), (0,), (13,), ) gooddata = \ ( (1, '--01--Z', 1), ((2,), '--02--Z', 2), ((10,), '--10--Z', 10), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('--01 --Z', N), ('--03--z', N), # Invalid ranges ('--00--Z', N), ('--13--Z', N), # Whitespace (ws + '--01--Z' + ws, 1), # No timezones ('--03--', 3), # Non-zulu ('--03---07:08', 3), ('--03--+07:08', 2), # Edgepoints (ranges) ('--01--Z', 1), ('--12--Z', 12), # Edgepoints (crossing boundaries) ('--01--+07:08', 12), ('--12---07:08', 12), ) for t in (gMonthType, monthType): self.allTests(t, baddata, gooddata, parsedata) def testGDayAndRecurringDay(self): baddata = \ ( 'hello', ('hello',), (3, 4,), (1, 2, 3, 4, 5, 6, 7, 8, 9, 10), (2.5,), (0,), (32,), ) gooddata = \ ( (1, '---01Z', 1), ((2,), '---02Z', 2), ((10,), '---10Z', 10), ) parsedata = \ ( # Some strings that won't match the r.e. ('hello', N), ('---01 Z', N), ('---03z', N), # Invalid ranges ('---00Z', N), ('---32Z', N), # Whitespace (ws + '---01Z' + ws, 1), # No timezones ('---03', 3), # Non-zulu ('---03-07:08', 3), ('---03+07:08', 2), # Edgepoints (ranges) ('---01Z', 1), ('---31Z', 31), # Edgepoints (crossing boundaries) ('---01+07:08', 31), ('---31-07:08', 31), ) for t in (gDayType, recurringDayType): self.allTests(t, baddata, gooddata, parsedata) def testInteger(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}) t = integerType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (10, 23, 1111111111111111111111111111111111111111111111111111): x = integerType(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('10 000', N), ('1', 1), ('123456789012345678901234567890', 123456789012345678901234567890), (ws + '12' + ws, 12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testNonPositiveInteger(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, 1, 23) for t in (nonPositiveIntegerType, non_Positive_IntegerType): for i in test: try: t(i) raise AssertionError("instantiated a t with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (0, -23, -1111111111111111111111111111111111111111111111111): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('1', N), ('0', 0), ('-1', -1), ('-123456789012345678901234567890', -123456789012345678901234567890), (ws + '-12' + ws, -12)) for i in test: try: if t == nonPositiveIntegerType: n = t.__name__[:-4] else: n = 'non-positive-integer' z = parseSOAPRPC(self.build_xml(t._validURIs[0], n, i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testNegativeInteger(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, 0, 23) for t in (negativeIntegerType, negative_IntegerType): for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (-1, -23, -111111111111111111111111111111111111111111111111): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('1', N), ('0', N), ('-1', -1), ('-123456789012345678901234567890', -123456789012345678901234567890), (ws + '-12' + ws, -12)) for i in test: try: if t == negativeIntegerType: n = t.__name__[:-4] else: n = 'negative-integer' z = parseSOAPRPC(self.build_xml(t._validURIs[0], n, i[0])) if z != i[1]: raise AssertionError("expected %s, got %s" % (i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testLong(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -9223372036854775809, 9223372036854775808) t = longType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (-1, -23, -9223372036854775808, 9223372036854775807): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-9223372036854775809', N), ('9223372036854775808', N), ('-1', -1), ('0', 0), ('1', 1), ('-9223372036854775808', -9223372036854775808), ('9223372036854775807', 9223372036854775807), (ws + '-12' + ws, -12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testInt(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -2147483649, 2147483648) t = intType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (-1, -23, -2147483648, 2147483647): x = intType(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-2147483649', N), ('2147483648', N), ('-1', -1), ('0', 0), ('1', 1), ('-2147483648', -2147483648), ('2147483647', 2147483647), (ws + '-12' + ws, -12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testShort(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -32769, 32768) t = shortType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (-1, -23, -32768, 32767): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-32769', N), ('32768', N), ('-1', -1), ('0', 0), ('1', 1), ('-32768', -32768), ('32767', 32767), (ws + '-12' + ws, -12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testByte(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -129, 128) t = byteType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (-1, -23, -128, 127): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-129', N), ('128', N), ('-1', -1), ('0', 0), ('1', 1), ('-128', -128), ('127', 127), (ws + '-12' + ws, -12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testNonNegativeInteger(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -42, -1) for t in (nonNegativeIntegerType, non_Negative_IntegerType): for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (0, 1, 23, 111111111111111111111111111111111111111111111111): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-1', N), ('0', 0), ('1', 1), ('123456789012345678901234567890', 123456789012345678901234567890), (ws + '12' + ws, 12)) for i in test: try: if t == nonNegativeIntegerType: n = t.__name__[:-4] else: n = 'non-negative-integer' z = parseSOAPRPC(self.build_xml(t._validURIs[0], n, i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testUnsignedLong(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -42, -1, 18446744073709551616) t = unsignedLongType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (0, 23, 18446744073709551615): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-1', N), ('18446744073709551616', N), ('0', 0), ('1', 1), ('18446744073709551615', 18446744073709551615), (ws + '12' + ws, 12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testUnsignedInt(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -42, -1, 4294967296) t = unsignedIntType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (0, 23, 4294967295): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-1', N), ('4294967296', N), ('0', 0), ('1', 1), ('4294967295', 4294967295), (ws + '12' + ws, 12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testUnsignedShort(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -42, -1, 65536) t = unsignedShortType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (0, 23, 65535): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-1', N), ('65536', N), ('0', 0), ('1', 1), ('65535', 65535), (ws + '12' + ws, 12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testUnsignedByte(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -42, -1, 256) t = unsignedByteType for i in test: try: t(i) raise AssertionError("instantiated a %s with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (0, 23, 255): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-1', N), ('256', N), ('0', 0), ('1', 1), ('255', 255), (ws + '12' + ws, 12)) for i in test: try: z = parseSOAPRPC(self.build_xml(t._validURIs[0], t.__name__[:-4], i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testPositiveInteger(self): # First some things that shouldn't be valid test = ('hello', 3.14, (), [], {}, -42, -1, 0) for t in (positiveIntegerType, positive_IntegerType): for i in test: try: t(i) raise AssertionError("instantiated a t with a bad value (%s)" % \ (t.__name__, repr(i))) except AssertionError: raise except ValueError: pass # Now some things that should for i in (1, 23, 1111111111111111111111111111111111111111111111111111): x = t(i) d = x._marshalData() if d != str(i): raise AssertionError("expected %d, got %s" % (i, d)) y = buildSOAP(x) z = parseSOAPRPC(y) if z != i: raise AssertionError("expected %s, got %s" % (repr(i), repr(z))) # Now test parsing, both valid and invalid test = (('hello', N), ('3.14', N), ('-10 000', N), ('-1', N), ('0', N), ('1', 1), ('123456789012345678901234567890', 123456789012345678901234567890), (ws + '12' + ws, 12)) for i in test: try: if t == positiveIntegerType: n = t.__name__[:-4] else: n = 'positive-integer' z = parseSOAPRPC(self.build_xml(t._validURIs[0], n, i[0])) if z != i[1]: raise AssertionError("%s: expected %s, got %s" % \ (i[0], i[1], repr(z))) except AssertionError: raise except: if i[1] != N: raise AssertionError("parsing %s as %s threw exception %s:%s" % \ (i[0], t.__name__, sys.exc_info()[0], sys.exc_info()[1])) def testUntyped(self): # Make sure untypedType really isn't typed a = stringType('hello', name = 'a') b = untypedType('earth', name = 'b') x = buildSOAP((a, b)) #print "x=",x self.assertTrue(x.find('hello') != -1) self.assertTrue(x.find('earth') != -1) # Now some Array tests def testArray(self): env = ''' %s ''' xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[4]" SOAP-ENC:offset="[2]" xsi:type="SOAP-ENC:Array"> <_2 SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"> 1 2 <_3 SOAP-ENC:arrayType="xsd:int[2]" xsi:type="SOAP-ENC:Array"> 3 4 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [None, None, [1, 2], [3, 4]]) xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[3,4,2]" SOAP-ENC:offset="[17]" xsi:type="SOAP-ENC:Array"> 1 2 3 4 5 6 7 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [ [[None, None], [None, None], [None, None], [None, None]], [[None, None], [None, None], [None, None], [None, None]], [[None, 1], [2, 3], [4, 5], [6, 7]] ]) xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[3,4,2]" xsi:type="SOAP-ENC:Array"> -17 13 -22 1 17 23 6 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [ [[None, 1], [None, None], [None, None], [6, None]], [[None, None], [None, None], [None, 13], [None, None]], [[None, 17], [None, None], [None, None], [-22, 23]] ]) xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[4]" SOAP-ENC:offset="[3]" xsi:type="SOAP-ENC:Array"> 2 0 1 3 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [0, 1, 2, 3]) xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,3,4]" SOAP-ENC:offset="[23]" xsi:type="SOAP-ENC:Array"> ''' x = parseSOAPRPC(xml) self.assertEqual( x , [ [ [None, None, None, None], [None, None, None, None], [None, None, None, None], ], [ [None, None, None, None], [None, None, None, None], [None, None, None, None], ] ]) xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[4]" SOAP-ENC:offset="[3]" xsi:type="SOAP-ENC:Array"> 2 3 ''' try: x = parseSOAPRPC(xml) raise AssertionError("full array parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,0,4]" xsi:type="SOAP-ENC:Array"> ''' try: x = parseSOAPRPC(xml) raise AssertionError("array with bad dimension (0) parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,3,-4]" xsi:type="SOAP-ENC:Array"> ''' try: x = parseSOAPRPC(xml) raise AssertionError("array with bad dimension (negative) parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,3,4.4]" xsi:type="SOAP-ENC:Array"> ''' try: x = parseSOAPRPC(xml) raise AssertionError("array with bad dimension (non-integral) parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,hello,4]" xsi:type="SOAP-ENC:Array"> ''' try: x = parseSOAPRPC(xml) raise AssertionError("array with bad dimension (non-numeric) parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,3,4]" SOAP-ENC:offset="[-4]" xsi:type="SOAP-ENC:Array"> ''' try: x = parseSOAPRPC(xml) raise AssertionError("array with too large offset parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,3,4]" SOAP-ENC:offset="[24]" xsi:type="SOAP-ENC:Array"> ''' try: x = parseSOAPRPC(xml) raise AssertionError("array with too large offset parsed") except AssertionError: raise except: pass xml = env % ''' <_1 SOAP-ENC:arrayType="xsd:int[2,3,4]" xsi:type="SOAP-ENC:Array"> 2 3 ''' try: x = parseSOAPRPC(xml) raise AssertionError("full array parsed") except AssertionError: raise except: pass xml = env % ''' 3 4 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [3, 4]) xml = env % ''' 12345 6.789 Of Mans First Disobedience, and the Fruit Of that Forbidden Tree, whose mortal tast Brought Death into the World, and all our woe, http://www.dartmouth.edu/~milton/reading_room/ ''' x = parseSOAPRPC(xml) self.assertEqual( x , [12345, 6.789, '''Of Mans First Disobedience, and the Fruit Of that Forbidden Tree, whose mortal tast Brought Death into the World, and all our woe,''', 'http://www.dartmouth.edu/~milton/reading_room/']) xml = env % ''' Apple 1.56 Peach 1.48 ''' #x = parseSOAPRPC(xml) #print "x=",x xml = env % ''' r1c1 r1c2 r1c3 r2c1 r2c2 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [['r1c1', 'r1c2', 'r1c3'], ['r2c1', 'r2c2'], ['r2c1', 'r2c2']]) xml = env % ''' r1c1 r1c2 r1c3 r2c1 r2c2 r2c3 ''' x = parseSOAPRPC(xml) self.assertEqual( x , [['r1c1', 'r1c2', 'r1c3'], ['r2c1', 'r2c2', 'r2c3']]) xml = env % ''' The third element The fourth element ''' x = parseSOAPRPC(xml) self.assertEqual( x , [None, None, 'The third element', 'The fourth element', None]) xml = env % ''' Third row, third col Eighth row, third col ''' x = parseSOAPRPC(xml) # Example using key data def testKeyData(self): xml = ''' Success Valid mailto:actzerotestkeyname MIIDPjCCAqegAwIBAgIEOroMvDANBgkqhkiG9w0BAQUFADAxMQswCQYDVQQGEwJVI3nlMkH84ZdPKIyz60sNcVEwJ8kF+B6ZVNimCF+r7BWgLi/Dolce5CpbfMMyexZ+UQEMADrc7331eYS891KXSDQx mailto:actzerotestkeyname wgmV2FY6MBKvtaMmCvCoNi/0hycZkiPKC2PXjRLJKFJ5wjNfF+vWsQQUXxOKUQnu HjJqRkx90jJvnEzW3j9FlZFQcZTfJbE0v6BXhhSre2kZvkgcOERmDMeMs//oEA4u epnedUwrkPzedWU9AL7c/oN7rk65UuPWf7V8c/4E9bc= AQAB 9GKuRC3ISwE9aEatzDKW0WIp+P/ufOvCxy9d5jVglLaRiTTIelHoGKCE6cDG62HYOu/3ebce6M7Z6LX6l1J9pB5PUx+f2DaMYYEGuOtNA7/ei5Ga/mibRBCehQIcN6FF6ESFOwAJBRLajj+orgYSy0u1sTCla0V4nSBrYA2H6lx8mD3qfDJ4hie7nU0YqZxy50F9f9UxXKIVSeutyIIBjWDDKv0kVpKy7OUerOaZXOW6HBohXuV74kXMUZu+MpLIkMHOrhJeo+edfhmeFuw4kCo5it6GkrOKrGs6zo1hSxWp7uuvKAPbvUrumC6sTsTxAUg4KTGq85IUnBTYI40Q9TZtzMcONtrWfIIF23/7NJyOmygBaFa4wFqHxe7j2gSWCQRv2fPwXo/AAJTeKwsUIY8OgmANHHbFVqJEeg27jbCuSaQFxWD7ms240YurTb55HBLk6JSufDl0CUbxoUgjrDB++gUb8oalroWDIb5NcZ94QER+HiTQfB11HcPDHvONnzk/n+iF+Mcri53ZbAButnfp2x87sh6RedeiUUWruYA4eonRq5+aj2I9cIrGLQaLemna1AQ+PyD2SMelBLukfR7GUc7zaSPjPJh2W/aYAJSyjM98g6ABNntdfhuf+6jRYnYFqSXZL1W1JPf92OMOfwfuXTE2K68sNwCRhcbHDLM= ''' x = parseSOAPRPC(xml) def testZeroLengthTypedArray(self): """ Test that zero length typed arrays maintain thier type information when converted to a SOAP message. """ empty_int = typedArrayType(typed="int") empty_int_message = buildSOAP( empty_int ) self.assertNotEqual( re.search("xsd:int\[0\]", empty_int_message), None ) if __name__ == '__main__': print(""" NOTE: The 'testArray' test will fail because 'referenced' elements are included in the return object. This is a known shortcoming of the current version of SOAPpy. All other tests should succeed. """) unittest.main()