summaryrefslogtreecommitdiff
path: root/tests/memoryview/cythonarray.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/memoryview/cythonarray.pyx')
-rw-r--r--tests/memoryview/cythonarray.pyx38
1 files changed, 37 insertions, 1 deletions
diff --git a/tests/memoryview/cythonarray.pyx b/tests/memoryview/cythonarray.pyx
index 0dc823581..15d61d086 100644
--- a/tests/memoryview/cythonarray.pyx
+++ b/tests/memoryview/cythonarray.pyx
@@ -130,7 +130,7 @@ cdef int *getp(int dim1=10, int dim2=10, dim3=1) except NULL:
return p
-cdef void callback_free_data(void *p):
+cdef void callback_free_data(void *p) noexcept:
print 'callback free data called'
free(p)
@@ -286,3 +286,39 @@ def test_char_array_in_python_api(*shape):
arr = array(shape=shape, itemsize=sizeof(char), format='c', mode='c')
arr[:] = b'x'
return arr
+
+def test_is_Sequence():
+ """
+ >>> test_is_Sequence()
+ 1
+ 1
+ True
+ """
+ import sys
+ if sys.version_info < (3, 3):
+ from collections import Sequence
+ else:
+ from collections.abc import Sequence
+
+ arr = array(shape=(5,), itemsize=sizeof(char), format='c', mode='c')
+ for i in range(arr.shape[0]):
+ arr[i] = f'{i}'.encode('ascii')
+ print(arr.count(b'1')) # test for presence of added collection method
+ print(arr.index(b'1')) # test for presence of added collection method
+
+ if sys.version_info >= (3, 10):
+ # test structural pattern match in Python
+ # (because Cython hasn't implemented it yet, and because the details
+ # of what Python considers a sequence are important)
+ globs = {'arr': arr}
+ exec("""
+match arr:
+ case [*_]:
+ res = True
+ case _:
+ res = False
+""", globs)
+ assert globs['res']
+
+ return isinstance(arr, Sequence)
+