summaryrefslogtreecommitdiff
path: root/tests/run/ctuple.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/ctuple.pyx')
-rw-r--r--tests/run/ctuple.pyx49
1 files changed, 47 insertions, 2 deletions
diff --git a/tests/run/ctuple.pyx b/tests/run/ctuple.pyx
index 235265bb1..88cfdddfb 100644
--- a/tests/run/ctuple.pyx
+++ b/tests/run/ctuple.pyx
@@ -1,5 +1,8 @@
+# mode: run
+
import cython
+
def simple_convert(*o):
"""
>>> simple_convert(1, 2)
@@ -8,15 +11,35 @@ def simple_convert(*o):
>>> simple_convert(1)
Traceback (most recent call last):
...
- TypeError: Expected a tuple of size 2, got tuple
+ TypeError: Expected a sequence of size 2, got size 1
>>> simple_convert(1, 2, 3)
Traceback (most recent call last):
...
- TypeError: Expected a tuple of size 2, got tuple
+ TypeError: Expected a sequence of size 2, got size 3
"""
cdef (int, double) xy = o
return xy
+
+def convert_from_list(*o):
+ """
+ >>> convert_from_list(1, 2)
+ (1, 2.0)
+
+ >>> convert_from_list(1)
+ Traceback (most recent call last):
+ ...
+ TypeError: Expected a sequence of size 2, got size 1
+ >>> convert_from_list(1, 2, 3)
+ Traceback (most recent call last):
+ ...
+ TypeError: Expected a sequence of size 2, got size 3
+ """
+ cdef object values = list(o)
+ cdef (int, double) xy = values
+ return xy
+
+
def indexing((int, double) xy):
"""
>>> indexing((1, 2))
@@ -142,6 +165,17 @@ cpdef (int, double) cpdef_ctuple_return_type(int x, double y):
return x, y
+def cast_to_ctuple(*o):
+ """
+ >>> cast_to_ctuple(1, 2.)
+ (1, 2.0)
+ """
+ cdef int x
+ cdef double y
+ x, y = <(int, double)>o
+ return x, y
+
+
@cython.infer_types(True)
def test_type_inference():
"""
@@ -214,6 +248,17 @@ def test_mul((int, int) ab, int c):
"""
return ab * c
+def test_mul_to_ctuple((int, int) ab, int c):
+ """
+ >>> test_mul_to_ctuple((1, 2), 2)
+ (1, 2, 1, 2)
+ >>> test_mul_to_ctuple((1, 2), 3)
+ Traceback (most recent call last):
+ TypeError: Expected a sequence of size 4, got size 6
+ """
+ result: tuple[cython.int, cython.int, cython.int, cython.int] = ab * c
+ return result
+
def test_unop((int, int) ab):
"""
>>> test_unop((1, 2))