Ejemplo n.º 1
0
def test_objects_unary_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.nary_expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['nary_expression'])
    tree.child(1).data = 'unary_operator'
    unary_expression = ExpressionVisitor().unary_expression
    patch.object(ExpressionVisitor, 'unary_expression')
    r = unary_expression(tree)
    op = tree.unary_operator.child(0)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, op, [ExpressionVisitor.unary_expression(tree.child(1))])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 2
0
def test_objects_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['nary_expression'])
    tree.first_child().data = 'unary_operator'
    tree.children = ['!', 1]
    expression = ExpressionVisitor().expression
    patch.object(ExpressionVisitor, 'expression')
    r = expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, tree.first_child().child(0), [
            ExpressionVisitor.expression(tree.child(1))
        ])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 3
0
def test_objects_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.expression works with two nodes
    """
    patch.many(ExpressionVisitor, ["nary_expression"])
    tree.first_child().data = "unary_operator"
    tree.children = ["!", 1]
    expression = ExpressionVisitor().expression
    patch.object(ExpressionVisitor, "expression")
    r = expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree,
        tree.first_child().child(0),
        [ExpressionVisitor.expression(tree.child(1))],
    )
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 4
0
def test_objects_mul_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.mul_expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['nary_expression',
                                   'unary_expression'])
    tree.child(1).data = 'mul_operator'
    tree.children = [1, '*', 2]
    mul_expression = ExpressionVisitor().mul_expression
    patch.object(ExpressionVisitor, 'mul_expression')
    r = mul_expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, tree.child(1).child(0), [
            ExpressionVisitor.mul_expression(tree.child(0)),
            ExpressionVisitor.unary_expression(tree.child(2))
        ])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 5
0
def test_objects_pow_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.pow_expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['nary_expression',
                                   'primary_expression',
                                   'unary_expression'])
    tree.child(1).child(0).type = 'POWER'
    tree.children = [1, '+', 2]
    tree.child(1).data = 'pow_operator'
    r = ExpressionVisitor().pow_expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, tree.child(1).child(0), [
            ExpressionVisitor.primary_expression(tree.child(0)),
            ExpressionVisitor.unary_expression(tree.child(2))
        ])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 6
0
def test_objects_cmp_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.and_expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['nary_expression',
                                   'arith_expression'])
    tree.child(1).data = 'cmp_operator'
    tree.children = [1, '==', 2]
    cmp_expression = ExpressionVisitor().cmp_expression
    patch.object(ExpressionVisitor, 'cmp_expression')
    r = cmp_expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, tree.child(1).child(0), [
            ExpressionVisitor.cmp_expression(tree.child(0)),
            ExpressionVisitor.arith_expression(tree.child(2)),
        ])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 7
0
def test_objects_and_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.and_expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['nary_expression',
                                   'cmp_expression'])
    tree.child(1).type = 'AND'
    tree.children = [1, 'and', 2]
    and_expression = ExpressionVisitor().and_expression
    patch.object(ExpressionVisitor, 'and_expression')
    r = and_expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, tree.child(1), [
            ExpressionVisitor.and_expression(tree.child(0)),
            ExpressionVisitor.cmp_expression(tree.child(2)),
        ])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 8
0
def test_objects_arith_expression_two(patch, tree):
    """
    Ensures ExpressionVisitor.arith_expression works with two nodes
    """
    patch.many(ExpressionVisitor, ['mul_expression', 'nary_expression'])
    tree.child(1).data = 'arith_operator'
    tree.children = [1, '+', 2]
    arith_expression = ExpressionVisitor().arith_expression
    patch.object(ExpressionVisitor, 'arith_expression')
    r = arith_expression(tree)
    op_type = tree.child(1).child(0)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree, op_type, values=[
            ExpressionVisitor.arith_expression(tree.child(0)),
            ExpressionVisitor.mul_expression(tree.children[2])
        ])
    assert r == ExpressionVisitor.nary_expression()
Ejemplo n.º 9
0
def test_objects_expression_three(patch, tree):
    """
    Ensures ExpressionVisitor.expression works with three nodes
    """
    patch.many(ExpressionVisitor, ["nary_expression"])
    tree.child(1).data = "mul_operator"
    tree.children = [1, "*", 2]
    expression = ExpressionVisitor().expression
    patch.object(ExpressionVisitor, "expression")
    r = expression(tree)
    ExpressionVisitor.nary_expression.assert_called_with(
        tree,
        tree.child(1).child(0),
        [
            ExpressionVisitor.expression(tree.first_child()),
            ExpressionVisitor.expression(tree.child(2)),
        ],
    )
    assert r == ExpressionVisitor.nary_expression()