Fix passing Dict/Array based UserType as params
Change-Id: I732c1c292a63a1ec4e6cf341c8268dfe4a600e06
This commit is contained in:
parent
ea9f71d5f2
commit
2bb9362a45
@ -8,6 +8,7 @@ Changes
|
||||
* Allow disabling complex types auto-register
|
||||
* Documentation edits
|
||||
* Various documentation build fixes
|
||||
* Fix passing Dict and Array based UserType as params
|
||||
|
||||
0.6.1 (2014-05-02)
|
||||
------------------
|
||||
|
@ -165,6 +165,14 @@ def dict_from_params(datatype, params, path, hit_paths):
|
||||
for key in keys))
|
||||
|
||||
|
||||
@from_params.when_type(UserType)
|
||||
def usertype_from_params(datatype, params, path, hit_paths):
|
||||
value = from_params(datatype.basetype, params, path, hit_paths)
|
||||
if value is not Unset:
|
||||
return datatype.frombasetype(value)
|
||||
return Unset
|
||||
|
||||
|
||||
def args_from_args(funcdef, args, kwargs):
|
||||
newargs = []
|
||||
for argdef, arg in zip(funcdef.arguments[:len(args)], args):
|
||||
|
@ -14,6 +14,10 @@ class MyUserType(UserType):
|
||||
basetype = str
|
||||
|
||||
|
||||
class DictBasedUserType(UserType):
|
||||
basetype = DictType(int, int)
|
||||
|
||||
|
||||
class TestProtocolsCommons(unittest.TestCase):
|
||||
def test_from_param_date(self):
|
||||
assert from_param(datetime.date, '2008-02-28') == \
|
||||
@ -55,6 +59,15 @@ class TestProtocolsCommons(unittest.TestCase):
|
||||
def test_from_params_dict_unset(self):
|
||||
assert from_params(DictType(int, str), {}, 'a', set()) is Unset
|
||||
|
||||
def test_from_params_usertype(self):
|
||||
value = from_params(
|
||||
DictBasedUserType(),
|
||||
{'a[2]': '2'},
|
||||
'a',
|
||||
set()
|
||||
)
|
||||
self.assertEqual(value, {2: 2})
|
||||
|
||||
def test_args_from_args_usertype(self):
|
||||
|
||||
class FakeType(UserType):
|
||||
|
Loading…
x
Reference in New Issue
Block a user