|
From: <bov...@us...> - 2006-12-19 21:30:31
|
Revision: 1309
http://svn.sourceforge.net/pywebsvcs/?rev=1309&view=rev
Author: boverhof
Date: 2006-12-19 13:30:26 -0800 (Tue, 19 Dec 2006)
Log Message:
-----------
M test/test_zsi.py
A test/test_list.py
M test/test_zsi_net.py
M ZSI/TC.py
M ZSI/TCtimes.py
-- patch for [ 1615921 ] StringIO used but not imported in TC.py
-- added unittest for List
-- noticed in TCtimes there is problematic support of miliseconds, I think this was added
before last rc. Cant stuff ms in time_struct, need to use datetime
for this.
Modified Paths:
--------------
trunk/zsi/ZSI/TC.py
trunk/zsi/ZSI/TCtimes.py
trunk/zsi/test/test_zsi.py
trunk/zsi/test/test_zsi_net.py
Added Paths:
-----------
trunk/zsi/test/test_list.py
Modified: trunk/zsi/ZSI/TC.py
===================================================================
--- trunk/zsi/ZSI/TC.py 2006-12-19 01:24:09 UTC (rev 1308)
+++ trunk/zsi/ZSI/TC.py 2006-12-19 21:30:26 UTC (rev 1309)
@@ -22,9 +22,9 @@
from urllib import unquote as urldecode, quote as urlencode
from binascii import unhexlify as hexdecode, hexlify as hexencode
try:
- import cStringIO as StringIO
+ from cStringIO import StringIO
except ImportError:
- import StringIO
+ from StringIO import StringIO
_is_xsd_or_soap_ns = lambda ns: ns in [
@@ -1587,7 +1587,7 @@
itemTypeCode = pyclass(None)
if itemTypeCode is None:
- raise EvaluateException('Filed to locate %s' %self.itemTypeCode)
+ raise EvaluateException('Failed to locate %s' %str(self.itemTypeCode))
if hasattr(itemTypeCode, 'text_to_data') is False:
raise EvaluateException('TypeCode class %s missing text_to_data method' %itemTypeCode)
@@ -1600,7 +1600,8 @@
list are space separated.
'''
v = []
- for item in text.split(' '):
+ items = text.split()
+ for item in items:
v.append(self.itemTypeCode.text_to_data(item, elt, ps))
if self.pyclass is not None:
@@ -1616,9 +1617,7 @@
href = _find_href(elt)
if not href:
if self.nilled(elt, ps) is False:
- # No content, no HREF, not NIL: empty string
- return ""
- # No content, no HREF, and is NIL...
+ return []
if self.nillable is True:
return Nilled
raise EvaluateException('Required string missing',
@@ -1629,18 +1628,19 @@
self.checktype(elt, ps)
if self.nilled(elt, ps): return Nilled
- if len(_children(elt)) == 0: return ''
+ if len(_children(elt)) == 0: return []
v = self.simple_value(elt, ps)
return self.text_to_data(v, elt, ps)
+
def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw):
'''elt -- the current DOMWrapper element
sw -- soapWriter object
pyobj -- python object to serialize
'''
- if type(pyobj) not in _seqtypes:
- raise EvaluateException, 'expecting a list'
+ if pyobj is not None and type(pyobj) not in _seqtypes:
+ raise EvaluateException, 'expecting a list or None'
objid = _get_idstr(pyobj)
ns,n = self.get_name(name, objid)
@@ -1650,12 +1650,12 @@
return None
tc = self.itemTypeCode
- s = StringIO()
+ s = StringIO(); sep = ' '
for item in pyobj:
s.write(tc.get_formatted_content(item))
- s.write(' ')
+ s.write(sep)
- el.createAppendTextNode(textNode)
+ el.createAppendTextNode(s.getvalue())
class _AnyStrict(Any):
Modified: trunk/zsi/ZSI/TCtimes.py
===================================================================
--- trunk/zsi/ZSI/TCtimes.py 2006-12-19 01:24:09 UTC (rev 1308)
+++ trunk/zsi/ZSI/TCtimes.py 2006-12-19 21:30:26 UTC (rev 1309)
@@ -80,6 +80,13 @@
'''Convert a dictionary to a time tuple. Depends on key values in the
regexp pattern!
'''
+ # TODO: Adding a ms field to struct_time tuples is problematic
+ # since they don't have this field. Should use datetime
+ # which has a microseconds field, else no ms.. When mapping struct_time
+ # to gDateTime the last 3 fields are irrelevant, here using dummy values to make
+ # everything happy.
+ #
+
retval = _niltime[:]
for k,i in ( ('Y', 0), ('M', 1), ('D', 2), ('h', 3), ('m', 4), ):
v = d.get(k)
Added: trunk/zsi/test/test_list.py
===================================================================
--- trunk/zsi/test/test_list.py (rev 0)
+++ trunk/zsi/test/test_list.py 2006-12-19 21:30:26 UTC (rev 1309)
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+import unittest, time, datetime
+import ZSI
+from ZSI.writer import SoapWriter
+from ZSI import _get_element_nsuri_name
+from ZSI.schema import GED, TypeDefinition, ElementDeclaration
+from ZSI.parse import ParsedSoap
+from cStringIO import StringIO
+
+
+class TestList1_Def(ZSI.TC.List, TypeDefinition):
+ itemType = (u'http://www.w3.org/2001/XMLSchema', u'dateTime')
+ schema = "urn:test"
+ type = (schema, "tUsage")
+ def __init__(self, pname, **kw):
+ ZSI.TC.List.__init__(self, pname, **kw)
+
+
+class TestList2_Def(ZSI.TC.List, TypeDefinition):
+ itemType = ZSI.TC.gDateTime()
+ schema = "urn:test"
+ type = (schema, "tUsage")
+ def __init__(self, pname, **kw):
+ ZSI.TC.List.__init__(self, pname, **kw)
+
+
+class ListTestCase(unittest.TestCase):
+ "test List TypeCode"
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def check_list_defs(self):
+ gl = globals()
+ for klass in map(lambda h: gl[h], filter(lambda g: (g.startswith('TestList') and
+ issubclass(gl[g],ZSI.TC.List)), gl)):
+
+ typecode = klass('whatever', nillable=True)
+ data = None
+ for i in range(10):
+ sw = SoapWriter()
+ sw.serialize(data, typecode)
+ s = str(sw)
+ print s
+ ps = ParsedSoap(s); pyobj = ps.Parse(typecode)
+ assert pyobj == data, 'Data corruption expected "%s", got "%s"' %(str(data),str(pyobj))
+ if data is None:
+ data = []; continue;
+
+ #
+ # cut last 3 fields off: weekday (0-6, Monday is 0), Julian day (day in the year, 1-366),
+ # DST (Daylight Savings Time) flag (-1, 0 or 1)
+ #
+ utc = list(time.gmtime(i)[:-3]) + [999,0,0]
+ data.append(tuple(utc))
+
+
+def makeTestSuite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(ListTestCase, "check"))
+ return suite
+
+def main():
+ unittest.main(defaultTest="makeTestSuite")
+
+if __name__ == '__main__':
+ main()
+
Modified: trunk/zsi/test/test_zsi.py
===================================================================
--- trunk/zsi/test/test_zsi.py 2006-12-19 01:24:09 UTC (rev 1308)
+++ trunk/zsi/test/test_zsi.py 2006-12-19 21:30:26 UTC (rev 1309)
@@ -9,6 +9,7 @@
import test_t8
import test_t9
import test_union
+import test_list
import test_TCtimes
def makeTestSuite():
Modified: trunk/zsi/test/test_zsi_net.py
===================================================================
--- trunk/zsi/test/test_zsi_net.py 2006-12-19 01:24:09 UTC (rev 1308)
+++ trunk/zsi/test/test_zsi_net.py 2006-12-19 21:30:26 UTC (rev 1309)
@@ -11,6 +11,7 @@
import test_t9
import test_union
import test_TCtimes
+import test_list
def makeTestSuite():
return unittest.TestSuite(
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|