Skip to content

Commit 89769ee

Browse files
committed
formatting
1 parent dbfa33a commit 89769ee

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

tests/unit/test_cunumpy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
import numpy as np
22
import pytest
3+
34
import cunumpy as xp
45

6+
57
def test_to_numpy():
68
arr = xp.array([1, 2, 3])
79
# Even if it's already numpy, to_numpy should work
810
arr_np = xp.to_numpy(arr)
911
assert isinstance(arr_np, np.ndarray)
1012
assert np.array_equal(arr_np, [1, 2, 3])
1113

14+
1215
def test_to_cunumpy():
1316
arr = np.array([1, 2, 3])
1417
arr_xp = xp.to_cunumpy(arr)
1518
# Backend is numpy in tests usually
1619
assert isinstance(arr_xp, (np.ndarray, xp.ndarray))
1720

21+
1822
def test_get_backend_and_is_gpu_cpu():
1923
arr = np.array([1, 2, 3])
2024
assert xp.get_backend(arr) == "numpy"
2125
assert xp.is_gpu(arr) is False
2226
assert xp.is_cpu(arr) is True
2327

28+
2429
def test_use_backend():
2530
# Initial backend should be numpy (default) in this test environment
2631
assert "numpy" in xp.xp.__name__
@@ -32,6 +37,7 @@ def test_use_backend():
3237

3338
assert "numpy" in xp.xp.__name__
3439

40+
3541
def test_set_backend():
3642
# Set to numpy
3743
xp.set_backend("numpy")
@@ -45,6 +51,7 @@ def test_set_backend():
4551
arr2 = xp.array([2])
4652
assert arr2 is not None
4753

54+
4855
def test_backend_bools():
4956
with xp.use_backend("numpy"):
5057
assert xp.numpy_backend is True

tests/unit/test_cupy.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
1+
import numpy as np
12
import pytest
3+
24
import cunumpy as xp
3-
import numpy as np
5+
46

57
def test_to_cupy_available():
68
try:
79
import cupy as cp
810
except ImportError:
911
pytest.skip("CuPy not installed")
10-
12+
1113
with xp.use_backend("cupy"):
1214
arr = np.array([1, 2, 3])
1315
arr_cp = xp.to_cupy(arr)
1416
assert isinstance(arr_cp, cp.ndarray)
1517

18+
1619
def test_to_cupy_not_available():
1720
try:
1821
import cupy
22+
1923
pytest.skip("CuPy is installed, cannot test missing cupy error")
2024
except ImportError:
2125
pass
@@ -25,22 +29,24 @@ def test_to_cupy_not_available():
2529
with pytest.raises(ImportError):
2630
xp.to_cupy(arr)
2731

32+
2833
def test_synchronize():
2934
# Should not crash on any backend
3035
xp.synchronize()
31-
36+
3237
with xp.use_backend("numpy"):
3338
xp.synchronize()
34-
39+
3540
with xp.use_backend("cupy"):
3641
xp.synchronize()
3742

43+
3844
def test_xp_array_cupy():
3945
try:
4046
import cupy as cp
4147
except ImportError:
4248
pytest.skip("CuPy not installed")
43-
49+
4450
with xp.use_backend("cupy"):
4551
arr = xp.array([1, 2])
4652
arr *= 2

tests/unit/test_numpy.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
import numpy as np
22
import pytest
3+
34
import cunumpy as xp
45

6+
57
def test_xp_array():
68
with xp.use_backend("numpy"):
79
arr = xp.array([1, 2])
810
arr *= 2
911
assert isinstance(arr, np.ndarray)
1012
assert np.array_equal(arr, [2, 4])
1113

14+
1215
def test_numpy_symbols_accessible():
1316
"""All public numpy symbols must be reachable via cunumpy.
1417

0 commit comments

Comments
 (0)