leapfrogdevelopment/scio — pull request #3 by jstern (2013-03-06 05:14:57+00:00)
Title: Handle nil datetypes

So, now I've got this crazy service that's returning dates like:

Which causes the kinds of errors seen below when I call the service or add a few tests.

This PR does three things:

(1) Recognizes when adapt_args isn't going to give us what we need to instantiate a date or datetime, and bail returning None
(2) Recognizes when we're only setting the converted type of a child element as an attribute on the parent complex type due to that child having attributes, and decline to set the attribute if the only attribute is xsi:nil="true"
(3) Decline to set value._position when something slips into AttributeDescriptor.__set__ anyway because it has some other attribute in addition to xsi:nil="true", and then gets converted to None because of (1).

Actually, with (3) in place (2) isn't really needed, so I'd be happy to take it out if that simplifies things ... and I'm also a little uncomfortable with throwing away attributes on nil elements ... but it seems like a step forward from erroring out altogether? Maybe what we really need is some kind of Nil mixin...
======================================================================
ERROR: test_nil_datetypes.test_nil_simple_date
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jstern/Envs/scio-dev/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/jstern/working/main_repos/scio/tests/test_nil_datetypes.py", line 22, in test_nil_simple_date
nil = client.type.getNilDateResponse()
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 440, in __new__
inst = base.__new__(cls, *newarg, **newkw)
TypeError: Required argument 'year' (pos 1) not found

======================================================================
ERROR: test_nil_datetypes.test_nil_simple_datetime
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jstern/Envs/scio-dev/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/jstern/working/main_repos/scio/tests/test_nil_datetypes.py", line 37, in test_nil_simple_datetime
nil = client.type.getNilDateTimeResponse()
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 440, in __new__
inst = base.__new__(cls, *newarg, **newkw)
TypeError: Required argument 'year' (pos 1) not found

======================================================================
ERROR: test_nil_datetypes.test_deserialize_complex_nil_response
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jstern/Envs/scio-dev/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/Users/jstern/working/main_repos/scio/tests/test_nil_datetypes.py", line 42, in test_deserialize_complex_nil_response
resp = client.service.getNilDateAndDateTime('foo')
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 283, in __call__
response = self.send_request(request)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 299, in send_request
return self.client.send(self.method, request)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 153, in send
return self.handle_response(method, response)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 161, in handle_response
return method.output(body, header)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 1223, in __call__
result.append(part(body))
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 777, in __init__
setattr(self, name, el)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 994, in __set__
value = self._new(value)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 1019, in _new
val = self.type(value)
File "/Users/jstern/working/main_repos/scio/scio/client.py", line 440, in __new__
inst = base.__new__(cls, *newarg, **newkw)
TypeError: Required argument 'year' (pos 1) not found
-------------------- >> begin captured logging << --------------------
scio.client: DEBUG: Request: foo
scio.client: DEBUG: Response xml:

1955-11-05
1955-11-12T22:04:00

--------------------- >> end captured logging << ---------------------

----------------------------------------------------------------------
Ran 83 tests in 3.898s

FAILED (errors=3)