コード例 #1
0
def test_objects_arith_expression_one(patch, tree):
    """
    Ensures ExpressionVisitor.arith_expression works with one node
    """
    patch.many(ExpressionVisitor, ['mul_expression'])
    tree.child(0).data = 'mul_expression'
    tree.children = [1]
    r = ExpressionVisitor().arith_expression(tree)
    ExpressionVisitor.mul_expression.assert_called_with(tree.child(0))
    assert r == ExpressionVisitor.mul_expression()
コード例 #2
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()
コード例 #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()