Merge "Added a muranoPL-specific override of 'call'"
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
import six
|
import six
|
||||||
|
from yaql.language import expressions
|
||||||
from yaql.language import specs
|
from yaql.language import specs
|
||||||
from yaql.language import utils
|
from yaql.language import utils
|
||||||
from yaql.language import yaqltypes
|
from yaql.language import yaqltypes
|
||||||
@@ -201,6 +202,27 @@ def is_instance_of(obj, type_):
|
|||||||
return type_.type.is_compatible(obj)
|
return type_.type.is_compatible(obj)
|
||||||
|
|
||||||
|
|
||||||
|
@specs.name('call')
|
||||||
|
@specs.parameter('name', yaqltypes.String())
|
||||||
|
@specs.parameter('args', yaqltypes.Sequence())
|
||||||
|
@specs.parameter('kwargs', utils.MappingType)
|
||||||
|
@specs.inject('op_dot', yaqltypes.Delegate('#operator_.', with_context=True))
|
||||||
|
@specs.inject('base', yaqltypes.Super(with_context=True))
|
||||||
|
def call_func(context, op_dot, base, name, args, kwargs,
|
||||||
|
receiver=utils.NO_VALUE):
|
||||||
|
if isinstance(receiver, (dsl_types.MuranoObject,
|
||||||
|
dsl_types.MuranoTypeReference)):
|
||||||
|
kwargs = utils.filter_parameters_dict(kwargs)
|
||||||
|
args += tuple(
|
||||||
|
expressions.MappingRuleExpression(expressions.KeywordConstant(key),
|
||||||
|
value)
|
||||||
|
for key, value in six.iteritems(kwargs))
|
||||||
|
function = expressions.Function(name, *args)
|
||||||
|
return op_dot(context, receiver, function)
|
||||||
|
else:
|
||||||
|
return base(context, name, args, kwargs, receiver)
|
||||||
|
|
||||||
|
|
||||||
def register(context, runtime_version):
|
def register(context, runtime_version):
|
||||||
context.register_function(cast)
|
context.register_function(cast)
|
||||||
context.register_function(new)
|
context.register_function(new)
|
||||||
@@ -226,6 +248,7 @@ def register(context, runtime_version):
|
|||||||
context.register_function(type_legacy)
|
context.register_function(type_legacy)
|
||||||
else:
|
else:
|
||||||
context.register_function(type_)
|
context.register_function(type_)
|
||||||
|
context.register_function(call_func)
|
||||||
|
|
||||||
if runtime_version <= constants.RUNTIME_VERSION_1_1:
|
if runtime_version <= constants.RUNTIME_VERSION_1_1:
|
||||||
context = context.create_child_context()
|
context = context.create_child_context()
|
||||||
|
45
murano/tests/unit/dsl/meta/TestCall.yaml
Normal file
45
murano/tests/unit/dsl/meta/TestCall.yaml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
Name: OtherClass
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
toCall:
|
||||||
|
Arguments:
|
||||||
|
- source:
|
||||||
|
Contract: $.string()
|
||||||
|
- foo:
|
||||||
|
Contract: $
|
||||||
|
- bar:
|
||||||
|
Contract: $
|
||||||
|
- baz:
|
||||||
|
Contract: $
|
||||||
|
Body:
|
||||||
|
- trace('called as ' + $source)
|
||||||
|
|
||||||
|
staticMethod:
|
||||||
|
Usage: Static
|
||||||
|
Body:
|
||||||
|
- trace('called as static')
|
||||||
|
--- # ------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Name: TestCall
|
||||||
|
|
||||||
|
Methods:
|
||||||
|
.init:
|
||||||
|
Body:
|
||||||
|
- $.other: new(OtherClass)
|
||||||
|
|
||||||
|
testCall:
|
||||||
|
Body:
|
||||||
|
- call('toCall', ['call', 'foo'], {baz=>1, bar=>2}, $.other)
|
||||||
|
|
||||||
|
testMethodInvocation:
|
||||||
|
Body:
|
||||||
|
- $.other.toCall('method', 'foo', baz=>baz, bar=>bar)
|
||||||
|
|
||||||
|
testCallStatic:
|
||||||
|
Body:
|
||||||
|
- call('staticMethod', [], {}, :OtherClass)
|
||||||
|
|
||||||
|
testCallStaticAsInstance:
|
||||||
|
Body:
|
||||||
|
- call('staticMethod', [], {}, $.other)
|
||||||
|
--- # ------------------------------------------------------------------------
|
39
murano/tests/unit/dsl/test_call.py
Normal file
39
murano/tests/unit/dsl/test_call.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
# Copyright (c) 2015 Mirantis, Inc.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from murano.tests.unit.dsl.foundation import object_model as om
|
||||||
|
from murano.tests.unit.dsl.foundation import test_case
|
||||||
|
|
||||||
|
|
||||||
|
class TestCall(test_case.DslTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super(TestCall, self).setUp()
|
||||||
|
self._runner = self.new_runner(om.Object('TestCall'))
|
||||||
|
|
||||||
|
def test_call(self):
|
||||||
|
self._runner.testCall()
|
||||||
|
self.assertEqual(['called as call'], self._traces)
|
||||||
|
|
||||||
|
def test_method(self):
|
||||||
|
self._runner.testMethodInvocation()
|
||||||
|
self.assertEqual(['called as method'], self._traces)
|
||||||
|
|
||||||
|
def test_call_static(self):
|
||||||
|
self._runner.testCallStatic()
|
||||||
|
self.assertEqual(['called as static'], self._traces)
|
||||||
|
|
||||||
|
def test_call_static_as_instance(self):
|
||||||
|
self._runner.testCallStaticAsInstance()
|
||||||
|
self.assertEqual(['called as static'], self._traces)
|
Reference in New Issue
Block a user