Merge "Allows Spec::transform treat generators as list"
This commit is contained in:
commit
ed6372e674
@ -295,7 +295,9 @@ class TypeScheme(object):
|
||||
return utils.FrozenDict(result)
|
||||
|
||||
def _map_list(self, data, spec, context, path):
|
||||
if not utils.is_sequence(data):
|
||||
if utils.is_iterator(data):
|
||||
data = list(data)
|
||||
elif not utils.is_sequence(data):
|
||||
if data is None or data is dsl.NO_VALUE:
|
||||
data = []
|
||||
else:
|
||||
|
@ -163,3 +163,80 @@ Methods:
|
||||
|
||||
testAction:
|
||||
Scope: Public
|
||||
|
||||
---
|
||||
|
||||
Name: TestedTarget
|
||||
|
||||
Properties:
|
||||
prop:
|
||||
Contract:
|
||||
- $.string()
|
||||
Methods:
|
||||
foo:
|
||||
Arguments:
|
||||
- contracted:
|
||||
Contract:
|
||||
- $.string()
|
||||
Body:
|
||||
- Return: $contracted[2]
|
||||
|
||||
wildList:
|
||||
Arguments:
|
||||
- contracted:
|
||||
Contract:
|
||||
- $
|
||||
Body:
|
||||
- Return: $contracted[1][2]
|
||||
|
||||
wildContract:
|
||||
Arguments:
|
||||
- untyped:
|
||||
Contract: $
|
||||
Body:
|
||||
- Return: $untyped[1]
|
||||
|
||||
typedList:
|
||||
Arguments:
|
||||
- contracted:
|
||||
Contract:
|
||||
- [$.string()]
|
||||
Body:
|
||||
- Return: $contracted[1][2]
|
||||
|
||||
dictArgs:
|
||||
Arguments:
|
||||
- arg:
|
||||
Contract: {$.string(): [$.int()]}
|
||||
Body:
|
||||
- Return: $arg.get('a')[1]
|
||||
|
||||
---
|
||||
|
||||
Name: TestIteratorsTransform
|
||||
Methods:
|
||||
testProperties:
|
||||
Body:
|
||||
- $.target: new(TestedTarget, $this, prop => ['1', '2', '3'].where($))
|
||||
- Return: $.target.prop[2]
|
||||
testArgs:
|
||||
Body:
|
||||
- $.target: new(TestedTarget, $this)
|
||||
- Return: $.target.foo(['1', '2', '3'].where($))
|
||||
testUntypedArgs:
|
||||
Body:
|
||||
- $.target: new(TestedTarget, $this)
|
||||
- Return: $.target.wildContract(['1', '2', '3'].where($))
|
||||
testNotTypedListArgs:
|
||||
Body:
|
||||
- $.target: new(TestedTarget, $this)
|
||||
- Return: $.target.wildList([['1', '2', '3'].where($), ['4', '5', '6'].where($)].where($))
|
||||
testTypedList:
|
||||
Body:
|
||||
- $.target: new(TestedTarget, $this)
|
||||
- Return: $.target.typedList([['1', '2', '3'].where($), ['4', '5', '6'].where($)].where($))
|
||||
testListDict:
|
||||
Body:
|
||||
- $.target: new(TestedTarget, $this)
|
||||
- Return: $.target.dictArgs({'a' => [1, 2, 4].where($)})
|
||||
|
||||
|
@ -295,3 +295,19 @@ class TestContracts(test_case.DslTestCase):
|
||||
def test_default_expression(self):
|
||||
self.assertEqual('PROPERTY', self._runner.testDefaultExpression())
|
||||
self.assertEqual('value', self._runner.testDefaultExpression('value'))
|
||||
|
||||
|
||||
class TestContractsTransform(test_case.DslTestCase):
|
||||
def setUp(self):
|
||||
super(TestContractsTransform, self).setUp()
|
||||
self._runner = self.new_runner(om.Object('TestIteratorsTransform'))
|
||||
|
||||
def test_property(self):
|
||||
self.assertEqual('3', self._runner.testProperties())
|
||||
|
||||
def test_argument(self):
|
||||
self.assertEqual('3', self._runner.testArgs())
|
||||
self.assertEqual('2', self._runner.testUntypedArgs())
|
||||
self.assertEqual('6', self._runner.testNotTypedListArgs())
|
||||
self.assertEqual('6', self._runner.testTypedList())
|
||||
self.assertEqual(2, self._runner.testListDict())
|
||||
|
Loading…
x
Reference in New Issue
Block a user