Ejemplo n.º 1
0
def test_objects_cmp_expression_one(patch, tree):
    """
    Ensures ExpressionVisitor.and_expression works with one node
    """
    patch.many(ExpressionVisitor, ['arith_expression'])
    tree.child(0).data = 'arith_expression'
    tree.children = [1]
    r = ExpressionVisitor().cmp_expression(tree)
    ExpressionVisitor.arith_expression.assert_called_with(tree.child(0))
    assert r == ExpressionVisitor.arith_expression()
Ejemplo n.º 2
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.º 3
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()