Пример #1
0
def test_objects_values_filepath(patch, magic):
    patch.object(Objects, 'file')
    item = magic(type='FILEPATH')
    tree = magic(child=lambda x: item)
    result = Objects.values(tree)
    Objects.file.assert_called_with(item)
    assert result == Objects.file()
Пример #2
0
def test_objects_typed_argument(patch, tree):
    patch.object(Objects, 'values')
    result = Objects.typed_argument(tree)
    Objects.values.assert_called_with(Tree('anon', [tree.child(1)]))
    expected = {'$OBJECT': 'argument', 'name': tree.child().value,
                'argument': Objects.values()}
    assert result == expected
Пример #3
0
def test_objects_string(patch, tree):
    patch.object(Objects, 'unescape_string')
    patch.object(re, 'findall', return_value=[])
    result = Objects.string(tree)
    Objects.unescape_string.assert_called_with(tree)
    re.findall.assert_called_with(r'{([^}]*)}', Objects.unescape_string())
    assert result == {'$OBJECT': 'string', 'string': Objects.unescape_string()}
Пример #4
0
def test_objects_expression(patch, tree):
    patch.object(Objects, 'values')
    tree.child.return_value = None
    tree.values = None
    result = Objects.expression(tree)
    Objects.values.assert_called_with(tree.path_value.child())
    assert result == [Objects.values()]
Пример #5
0
def test_compiler_assignment_parent(patch, compiler, tree):
    patch.many(Objects, ['path', 'values'])
    patch.object(Compiler, 'add_line')
    compiler.assignment(tree, parent='1')
    args = [Objects.path(), Objects.values()]
    compiler.add_line.assert_called_with('set', tree.line(), args=args,
                                         parent='1')
Пример #6
0
def test_objects_function_arguments(patch, tree):
    patch.object(Objects, 'typed_argument')
    tree.find_data.return_value = ['typed_argument']
    result = Objects.function_arguments(tree)
    tree.find_data.assert_called_with('typed_argument')
    Objects.typed_argument.assert_called_with('typed_argument')
    assert result == [Objects.typed_argument()]
Пример #7
0
def test_objects_values_path(patch, magic):
    patch.object(Objects, 'path')
    item = magic(type='NAME')
    tree = magic(child=lambda x: item)
    result = Objects.values(tree)
    Objects.path.assert_called_with(tree)
    assert result == Objects.path()
Пример #8
0
def test_objects_values_method(patch, magic):
    patch.object(Objects, 'method')
    item = magic(data='path')
    tree = magic(child=lambda x: item)
    result = Objects.values(tree)
    Objects.method.assert_called_with(tree)
    assert result == Objects.method()
Пример #9
0
def test_objects_arguments(patch, tree):
    patch.object(Objects, 'argument')
    tree.find_data.return_value = filter(lambda x: x, ['argument'])
    result = Objects.arguments(tree)
    tree.find_data.assert_called_with('arguments')
    Objects.argument.assert_called_with('argument')
    assert result == [Objects.argument()]
Пример #10
0
def test_objects_absolute_expression(patch, tree):
    """
    Ensures Objects.absolute_expression calls expression
    """
    patch.many(Objects, ['expression'])
    tree.child(0).data = 'expression'
    Objects.absolute_expression(tree)
    Objects.expression.assert_called_with(tree.child(0))
Пример #11
0
def test_objects_resolve_operand_sum_to_parenthesis(patch, tree):
    """
    Ensures resolve_operand can resolve a parenthesis operand
    """
    patch.object(Objects, 'expression')
    result = Objects.resolve_operand(tree)
    Objects.expression.assert_called_with(tree.exponential.factor.expression)
    assert result == Objects.expression()
Пример #12
0
def test_objects_argument(patch, tree):
    patch.object(Objects, 'expression')
    result = Objects.argument(tree)
    assert tree.child.call_count == 2
    Objects.expression.assert_called_with(tree.child())
    expected = {'$OBJECT': 'argument', 'name': tree.child().value,
                'argument': Objects.expression()}
    assert result == expected
Пример #13
0
def test_objects_resolve_operand_multiplication_to_parenthesis(patch, tree):
    """
    Ensures resolve_operand can resolve a multiplication to a parenthesis.
    """
    patch.object(Objects, 'expression')
    tree.exponential = None
    result = Objects.resolve_operand(tree)
    Objects.expression.assert_called_with(tree.factor.expression)
    assert result == Objects.expression()
Пример #14
0
def test_objects_resolve_operand_number(patch, tree):
    """
    Ensures resolve_operand can resolve a number.
    """
    patch.object(Objects, 'number')
    tree.data = 'number'
    result = Objects.resolve_operand(tree)
    Objects.number.assert_called_with(tree)
    assert result == Objects.number()
Пример #15
0
def test_objects_names_string(patch, magic, tree):
    """
    Ensures that paths like x['y'] are compiled correctly
    """
    patch.object(Objects, 'string')
    tree.children = [magic(), Tree('fragment', [Tree('string', 'token')])]
    result = Objects.names(tree)
    Objects.string.assert_called_with(Tree('string', 'token'))
    assert result[1] == Objects.string()
Пример #16
0
def test_compiler_mutation_block_nested(patch, compiler, lines, tree):
    patch.many(Objects, ['entity', 'mutation'])
    patch.object(Compiler, 'chained_mutations', return_value=['chained'])
    tree.path = None
    compiler.mutation_block(tree, None)
    Compiler.chained_mutations.assert_called_with(tree.nested_block)
    args = [Objects.entity(), Objects.mutation(), 'chained', 'chained']
    kwargs = {'args': args, 'parent': None}
    lines.append.assert_called_with('mutation', tree.line(), **kwargs)
Пример #17
0
def test_objects_string_templating(patch):
    patch.object(Objects, 'path')
    patch.object(re, 'findall', return_value=['color'])
    tree = Tree('string', [Token('DOUBLE_QUOTED', '"{{color}}"')])
    result = Objects.string(tree)
    re.findall.assert_called_with(r'{{([^}]*)}}', '{{color}}')
    Objects.path.assert_called_with(Tree('path', [Token('WORD', 'color')]))
    assert result['string'] == '{}'
    assert result['values'] == [Objects.path()]
Пример #18
0
def test_objects_typed_argument(patch, tree):
    patch.object(Objects, 'values')
    result = Objects.typed_argument(tree)
    expected = {
        '$OBJECT': 'argument',
        'name': tree.node().child().value,
        'argument': Objects.values()
    }
    assert result == expected
Пример #19
0
def test_objects_resolve_operand_multiplication(patch, tree):
    """
    Ensures resolve_operand can resolve a multiplication tree.
    """
    patch.object(Objects, 'entity')
    tree.exponential.factor.expression = None
    result = Objects.resolve_operand(tree)
    Objects.entity.assert_called_with(tree.exponential.factor.entity)
    assert result == Objects.entity()
Пример #20
0
def test_objects_resolve_operand_exponential(patch, magic, tree):
    """
    Ensures resolve_operand can resolve an exponential tree
    """
    patch.object(Objects, 'expression')
    tree.exponential.children = [1, 2]
    result = Objects.resolve_operand(tree)
    Objects.expression.assert_called_with(tree.exponential)
    assert result == Objects.expression()
Пример #21
0
def test_objects_assertion_single_entity(patch, tree):
    """
    Ensures that Objects.assertion handles single entities
    """
    patch.many(Objects, ['expression'])
    Objects.expression.return_value = True
    result = Objects.assertion(tree)
    Objects.expression.assert_called_with(tree.expression)
    assert result == [Objects.expression()]
Пример #22
0
def test_objects_objects_key_path(patch, tree):
    """
    Ensures that objects like {x: 0} are compiled
    """
    patch.many(Objects, ['path', 'expression'])
    subtree = Tree('key_value', [Tree('path', ['path'])])
    tree.children = [subtree]
    result = Objects.objects(tree)
    assert result['items'][0][0] == Objects.path()
Пример #23
0
def test_objects_resolve_operand_children(patch, tree):
    """
    Ensures resolve_operand can resolve nested operands.
    """
    patch.object(Objects, 'expression')
    tree.children = [1, 2]
    result = Objects.resolve_operand(tree)
    Objects.expression.assert_called_with(tree)
    assert result == Objects.expression()
Пример #24
0
def test_objects_mutation_arguments(patch, magic):
    """
    Ensures that mutations objects with arguments are compiled correctly.
    """
    patch.object(Objects, 'arguments')
    tree = magic()
    result = Objects.mutation(tree)
    Objects.arguments.assert_called_with(tree)
    assert result['arguments'] == Objects.arguments()
Пример #25
0
def test_objects_primary_expression_two(patch, tree):
    """
    Ensures Objects.primary_expression works with a or_expression node
    """
    patch.many(Objects, ['entity', 'or_expression'])
    tree.child(0).data = 'or_expression'
    r = Objects.primary_expression(tree)
    Objects.or_expression.assert_called_with(tree.child(0))
    assert r == Objects.or_expression()
Пример #26
0
def test_objects_primary_expression_entity(patch, tree):
    """
    Ensures Objects.primary_expression works with an entity node
    """
    patch.many(Objects, ['entity'])
    tree.child(0).data = 'entity'
    r = Objects.primary_expression(tree)
    Objects.entity.assert_called_with(tree.entity)
    assert r == Objects.entity()
Пример #27
0
def test_objects_number():
    """
    Ensures that an int is compiled correctly.
    """
    tree = Tree('number', [Token('INT', '1')])
    assert Objects.number(tree) == 1
    tree = Tree('number', [Token('INT', '+1')])
    assert Objects.number(tree) == 1
    tree = Tree('number', [Token('INT', '-1')])
    assert Objects.number(tree) == -1
Пример #28
0
def test_objects_cmp_expression_one(patch, tree):
    """
    Ensures Objects.and_expression works with one node
    """
    patch.many(Objects, ['arith_expression'])
    tree.child(0).data = 'arith_expression'
    tree.children = [1]
    r = Objects.cmp_expression(tree)
    Objects.arith_expression.assert_called_with(tree.child(0))
    assert r == Objects.arith_expression()
Пример #29
0
def test_objects_pow_expression_one(patch, tree):
    """
    Ensures Objects.pow_expression works with one node
    """
    patch.many(Objects, ['primary_expression'])
    tree.child(0).data = 'primary_expression'
    tree.children = [1]
    r = Objects.pow_expression(tree)
    Objects.primary_expression.assert_called_with(tree.child(0))
    assert r == Objects.primary_expression()
Пример #30
0
def test_objects_names_path(patch, magic, tree):
    """
    Ensures that paths like x[y] are compiled correctly
    """
    patch.object(Objects, 'path')
    subtree = Tree('path', ['token'])
    tree.children = [magic(), Tree('fragment', [subtree])]
    result = Objects.names(tree)
    Objects.path.assert_called_with(subtree)
    assert result[1] == Objects.path()