summaryrefslogtreecommitdiff
path: root/tests/run/cascadedassignment.pyx
blob: 5bde089f74056c5fc5b684534e34a3766192885d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import cython

@cython.test_fail_if_path_exists(
    '//CascadedAssignmentNode//CoerceFromPyTypeNode',
    '//CascadedAssignmentNode//CoerceToPyTypeNode',
)
@cython.test_assert_path_exists('//CascadedAssignmentNode')
def test_cascaded_assignment_simple():
    """
    >>> test_cascaded_assignment_simple()
    5
    """
    a = b = c = 5
    return a

@cython.test_fail_if_path_exists(
    '//CascadedAssignmentNode//CoerceFromPyTypeNode',
    '//CascadedAssignmentNode//CoerceToPyTypeNode',
)
@cython.test_assert_path_exists('//CascadedAssignmentNode')
def test_cascaded_assignment_typed():
    """
    >>> test_cascaded_assignment_typed()
    int Python object double
    (5, 5, 5.0)
    """
    cdef int a
    cdef object b
    cdef double c

    a = b = c = 5

    print cython.typeof(a), cython.typeof(b), cython.typeof(c)
    return a, b, c

def test_cascaded_assignment_builtin_expr():
    """
    This test is useful as previously the rhs expr node got replaced resulting
    in CloneNode generating None in the C source.

    >>> test_cascaded_assignment_builtin_expr()
    (10.0, 10.0, 10.0)
    """
    a = b = c = float(10)
    return a, b, c

def expr():
    print "expr called"
    return 10

def test_cascaded_assignment_evaluate_expr():
    """
    >>> test_cascaded_assignment_evaluate_expr()
    expr called
    (10.0, 10.0, 10.0)
    """
    a = b = c = float(expr())
    return a, b, c