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()
def test_objects_expression_two_as(patch, tree): """ Ensures ExpressionVisitor.expression works with as """ patch.many(ExpressionVisitor, ['as_expression']) tree.child(1).data = 'as_operator' tree.children = ['!', 1] expression = ExpressionVisitor().expression patch.object(ExpressionVisitor, 'expression') r = expression(tree) ExpressionVisitor.as_expression.assert_called_with( tree, ExpressionVisitor.expression(tree.first_child()), ) assert r == ExpressionVisitor.as_expression()
def test_objects_expression_two_as(patch, tree): """ Ensures ExpressionVisitor.expression works with as """ patch.many(ExpressionVisitor, ["to_expression"]) tree.child(1).data = "to_operator" tree.children = ["!", 1] expression = ExpressionVisitor().expression patch.object(ExpressionVisitor, "expression") r = expression(tree) ExpressionVisitor.to_expression.assert_called_with( tree, ExpressionVisitor.expression(tree.first_child()), ) assert r == ExpressionVisitor.to_expression()
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()