summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authortynn <tynn.dev@gmail.com>2017-07-01 20:33:45 +0200
committerEric Wieser <wieser.eric@gmail.com>2018-04-24 21:52:42 -0700
commit1ec8f6d93ea150d79cfea6515ffe02f6d78753b2 (patch)
treee37a45a797c04098192f0c0214841c5f6f09e7db /numpy
parentd7d5cb3feccc1fc6cf57159e8b9fe0a733968706 (diff)
downloadnumpy-1ec8f6d93ea150d79cfea6515ffe02f6d78753b2.tar.gz
TST: Add tests for numpy.ctypeslib.as_array
Diffstat (limited to 'numpy')
-rw-r--r--numpy/tests/test_ctypeslib.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/numpy/tests/test_ctypeslib.py b/numpy/tests/test_ctypeslib.py
index 0f0d6dbc4..508a348c1 100644
--- a/numpy/tests/test_ctypeslib.py
+++ b/numpy/tests/test_ctypeslib.py
@@ -4,9 +4,9 @@ import sys
import pytest
import numpy as np
-from numpy.ctypeslib import ndpointer, load_library
+from numpy.ctypeslib import ndpointer, load_library, as_array
from numpy.distutils.misc_util import get_shared_lib_extension
-from numpy.testing import assert_, assert_raises
+from numpy.testing import assert_, assert_array_equal, assert_raises
try:
cdll = None
@@ -113,3 +113,25 @@ class TestNdpointer(object):
a1 = ndpointer(dtype=np.float64)
a2 = ndpointer(dtype=np.float64)
assert_(a1 == a2)
+
+class TestAsArray(object):
+ @pytest.mark.skipif(not _HAS_CTYPE,
+ reason="ctypes not available on this python installation")
+ def test_array(self):
+ from ctypes import c_int
+ at = c_int * 2
+ a = as_array(at(1, 2))
+ assert_(a.shape == (2,))
+ assert_array_equal(a, np.array([1, 2]))
+ a = as_array((at * 3)(at(1, 2), at(3, 4), at(5, 6)))
+ assert_(a.shape == (3, 2))
+ assert_array_equal(a, np.array([[1, 2], [3, 4], [5, 6]]))
+
+ @pytest.mark.skipif(not _HAS_CTYPE,
+ reason="ctypes not available on this python installation")
+ def test_pointer(self):
+ from ctypes import c_int, cast, POINTER
+ p = cast((c_int * 10)(*range(10)), POINTER(c_int))
+ a = as_array(p, (10,))
+ assert_(a.shape == (10,))
+ assert_array_equal(a, np.array(range(10)))