summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2020-05-05 16:11:57 +0200
committerStefan Behnel <stefan_ml@behnel.de>2020-05-05 16:11:57 +0200
commite1eb0a1cf972287d670e9640d735150349321253 (patch)
treeee5b0c11fd51b383fbebe1f4ce4d674c095a9f83
parent9ac5d81184d35cab4543d86e1e24d12378ca99e2 (diff)
downloadcython-e1eb0a1cf972287d670e9640d735150349321253.tar.gz
Tighten "numpy_attributes" test to assert that it's actually using a property call and not an attribute access.
Also add a test for the newly added "ndarray.data" property.
-rw-r--r--tests/run/numpy_attributes.pyx53
1 files changed, 50 insertions, 3 deletions
diff --git a/tests/run/numpy_attributes.pyx b/tests/run/numpy_attributes.pyx
index d99d4476d..f4c1ba956 100644
--- a/tests/run/numpy_attributes.pyx
+++ b/tests/run/numpy_attributes.pyx
@@ -1,37 +1,84 @@
# mode: run
# tag: numpy
+cimport cython
+
import numpy as np
cimport numpy as cnp
cnp.import_array()
+
+@cython.test_assert_path_exists(
+ "//ReturnStatNode",
+ "//ReturnStatNode//IndexNode",
+ "//ReturnStatNode//IndexNode//SimpleCallNode",
+)
+@cython.test_fail_if_path_exists(
+ "//ReturnStatNode//AttributeNode",
+)
def access_shape():
"""
>>> access_shape()
10
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
- 1e10 * np.ones((10, 10))
+ 1e10 * np.ones((10, 10))
return array_in.shape[0]
+
+@cython.test_assert_path_exists(
+ "//ReturnStatNode",
+ "//ReturnStatNode//SimpleCallNode",
+)
+@cython.test_fail_if_path_exists(
+ "//ReturnStatNode//AttributeNode",
+)
def access_size():
"""
>>> access_size()
100
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
- 1e10 * np.ones((10, 10))
+ 1e10 * np.ones((10, 10))
return array_in.size
+
+@cython.test_assert_path_exists(
+ "//ReturnStatNode",
+ "//ReturnStatNode//IndexNode",
+ "//ReturnStatNode//IndexNode//SimpleCallNode",
+)
+@cython.test_fail_if_path_exists(
+ "//ReturnStatNode//AttributeNode",
+)
def access_strides():
"""
>>> access_strides()
(80, 8)
"""
cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
- 1e10 * np.ones((10, 10), dtype=np.float64)
+ 1e10 * np.ones((10, 10), dtype=np.float64)
return (array_in.strides[0], array_in.strides[1])
+
+
+@cython.test_assert_path_exists(
+ "//ReturnStatNode",
+ "//ReturnStatNode//PrimaryCmpNode",
+ "//ReturnStatNode//PrimaryCmpNode//SimpleCallNode",
+)
+@cython.test_fail_if_path_exists(
+ "//ReturnStatNode//AttributeNode",
+)
+def access_data():
+ """
+ >>> access_data()
+ True
+ """
+ cdef cnp.ndarray[double, ndim=2, mode='c'] array_in = \
+ 1e10 * np.ones((10, 10), dtype=np.float64)
+
+ return array_in.data is not NULL