Skip to content

Commit 82365eb

Browse files
committed
Add a test that vendoring works
1 parent e996d22 commit 82365eb

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed

tests/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
Basic tests for the compat library
3+
4+
This only tests basic things like that vendoring works. The extensive tests
5+
are done by the array API test suite https://github.com/data-apis/array-api-tests
6+
7+
"""

tests/test_vendoring.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from pytest import skip
2+
3+
def test_vendoring_numpy():
4+
from vendor_test import uses_numpy
5+
uses_numpy._test_numpy()
6+
7+
8+
def test_vendoring_cupy():
9+
try:
10+
import cupy
11+
except ImportError:
12+
skip("CuPy is not installed")
13+
14+
from vendor_test import uses_cupy
15+
uses_cupy._test_cupy()

tests/vendor_test/__init__.py

Whitespace-only changes.

tests/vendor_test/uses_cupy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Basic test that vendoring works
2+
3+
from .vendored._compat import cupy as cp_compat
4+
5+
import cupy as cp
6+
7+
def _test_cupy():
8+
a = cp_compat.asarray([1., 2., 3.])
9+
b = cp_compat.arange(3, dtype=cp_compat.float32)
10+
11+
# cp.pow does not exist. Update this to use something else if it is added
12+
res = cp_compat.pow(a, b)
13+
assert res.dtype == cp_compat.float64 == cp.float64
14+
assert isinstance(a, cp.ndarray)
15+
assert isinstance(b, cp.ndarray)
16+
assert isinstance(res, cp.ndarray)
17+
18+
cp.testing.assert_allclose(res, [1., 2., 9.])

tests/vendor_test/uses_numpy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Basic test that vendoring works
2+
3+
from .vendored._compat import numpy as np_compat
4+
5+
import numpy as np
6+
7+
def _test_numpy():
8+
a = np_compat.asarray([1., 2., 3.])
9+
b = np_compat.arange(3, dtype=np_compat.float32)
10+
11+
# np.pow does not exist. Update this to use something else if it is added
12+
res = np_compat.pow(a, b)
13+
assert res.dtype == np_compat.float64 == np.float64
14+
assert isinstance(a, np.ndarray)
15+
assert isinstance(b, np.ndarray)
16+
assert isinstance(res, np.ndarray)
17+
18+
np.testing.assert_allclose(res, [1., 2., 9.])

tests/vendor_test/vendored/__init__.py

Whitespace-only changes.

tests/vendor_test/vendored/_compat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../array_api_compat/

0 commit comments

Comments
 (0)