1import cython
2
3@cython.test_fail_if_path_exists(
4    '//CascadedAssignmentNode//CoerceFromPyTypeNode',
5    '//CascadedAssignmentNode//CoerceToPyTypeNode',
6)
7@cython.test_assert_path_exists('//CascadedAssignmentNode')
8def test_cascaded_assignment_simple():
9    """
10    >>> test_cascaded_assignment_simple()
11    5
12    """
13    a = b = c = 5
14    return a
15
16@cython.test_fail_if_path_exists(
17    '//CascadedAssignmentNode//CoerceFromPyTypeNode',
18    '//CascadedAssignmentNode//CoerceToPyTypeNode',
19)
20@cython.test_assert_path_exists('//CascadedAssignmentNode')
21def test_cascaded_assignment_typed():
22    """
23    >>> test_cascaded_assignment_typed()
24    int Python object double
25    (5, 5, 5.0)
26    """
27    cdef int a
28    cdef object b
29    cdef double c
30
31    a = b = c = 5
32
33    print cython.typeof(a), cython.typeof(b), cython.typeof(c)
34    return a, b, c
35
36def test_cascaded_assignment_builtin_expr():
37    """
38    This test is useful as previously the rhs expr node got replaced resulting
39    in CloneNode generating None in the C source.
40
41    >>> test_cascaded_assignment_builtin_expr()
42    (10.0, 10.0, 10.0)
43    """
44    a = b = c = float(10)
45    return a, b, c
46
47def expr():
48    print "expr called"
49    return 10
50
51def test_cascaded_assignment_evaluate_expr():
52    """
53    >>> test_cascaded_assignment_evaluate_expr()
54    expr called
55    (10.0, 10.0, 10.0)
56    """
57    a = b = c = float(expr())
58    return a, b, c
59