Esempio n. 1
0
    def initialize(self, _context, host):
        environment = yaql_expression.YaqlExpression(
            "$host.find('io.murano.Environment').require()").evaluate(_context)

        self._queue = str('e%s-h%s' %
                          (environment.object_id, host.object_id)).lower()
        self._environment = environment
Esempio n. 2
0
    def test_needs_evaluation(self):
        testee = helpers.needs_evaluation
        parsed_expr = yaql.parse("string")
        yaql_expr = yaql_expression.YaqlExpression("string")

        self.assertTrue(testee(parsed_expr))
        self.assertTrue(testee(yaql_expr))
        self.assertTrue(testee({yaql_expr: 1}))
        self.assertTrue(testee({'label': yaql_expr}))
        self.assertTrue(testee([yaql_expr]))
Esempio n. 3
0
    def test_evaluate_calls(self):
        string = 'string'
        expected_calls = [
            mock.call(string),
            mock.call().evaluate(context=None)
        ]

        with mock.patch('yaql.parse') as mock_parse:
            yaql_expr = yaql_expression.YaqlExpression(string)
            yaql_expr.evaluate()

        self.assertEqual(expected_calls, mock_parse.mock_calls)
Esempio n. 4
0
    def test_match_returns(self):
        expr = yaql_expression.YaqlExpression('string')

        with mock.patch('yaql.parse'):
            self.assertTrue(expr.match('$some'))
            self.assertTrue(expr.match('$.someMore'))

        with mock.patch('yaql.parse') as parse_mock:
            parse_mock.side_effect = yaql.exceptions.YaqlGrammarException
            self.assertFalse(expr.match(''))

        with mock.patch('yaql.parse') as parse_mock:
            parse_mock.side_effect = yaql.exceptions.YaqlLexicalException
            self.assertFalse(expr.match(''))
Esempio n. 5
0
 def _generate_arguments_scheme(self, func):
     func_info = inspect.getargspec(func)
     data = [(name, {
         'Contract': yaql_expression.YaqlExpression('$')
     }) for name in func_info.args]
     if inspect.ismethod(func):
         data = data[1:]
     defaults = func_info.defaults or tuple()
     for i in xrange(len(defaults)):
         data[i + len(data) - len(defaults)][1]['Default'] = defaults[i]
     result = OrderedDict([(name,
                            typespec.ArgumentSpec(declaration,
                                                  self._namespace_resolver))
                           for name, declaration in data])
     if '_context' in result:
         del result['_context']
     return result
Esempio n. 6
0
def yaql_constructor(loader, node):
    value = loader.construct_scalar(node)
    return yaql_expression.YaqlExpression(value)
Esempio n. 7
0
 def __init__(self, Parallel, Limit=None):
     super(ParallelMacro, self).__init__(Parallel)
     if Limit:
         self._limit = yaql_expression.YaqlExpression(Limit)
     else:
         self._limit = len(self.code_block)
Esempio n. 8
0
    def test_expression(self):
        yaql_expr = yaql_expression.YaqlExpression('string')

        self.assertEqual('string', yaql_expr.expression())