Skip to content

Commit a3ff897

Browse files
authored
Extend third party tests (#2727)
The PR includes * migration of some tests from unittest to pytest * updates in FFT tests * new tests for `random.choice` This PR is intended to reflect alignment with the recent changes in origin repo of third party tests.
1 parent a97953e commit a3ff897

File tree

9 files changed

+1183
-359
lines changed

9 files changed

+1183
-359
lines changed

dpnp/tests/third_party/cupy/binary_tests/test_elementwise.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
from __future__ import annotations
22

3-
import unittest
4-
53
from dpnp.tests.third_party.cupy import testing
64

75

8-
class TestElementwise(unittest.TestCase):
6+
class TestElementwise:
97

108
@testing.for_int_dtypes()
119
@testing.numpy_cupy_array_equal()

dpnp/tests/third_party/cupy/binary_tests/test_packing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
from __future__ import annotations
22

33
import numpy
44
import pytest
@@ -11,7 +11,7 @@
1111
)
1212

1313

14-
class TestPacking(unittest.TestCase):
14+
class TestPacking:
1515

1616
@testing.for_int_dtypes()
1717
@testing.numpy_cupy_array_equal()

dpnp/tests/third_party/cupy/core_tests/test_array_function.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import unittest
1+
from __future__ import annotations
22

33
import numpy
44
import pytest
@@ -11,7 +11,7 @@
1111
)
1212

1313

14-
class TestArrayFunction(unittest.TestCase):
14+
class TestArrayFunction:
1515

1616
@testing.with_requires("numpy>=1.17.0")
1717
def test_array_function(self):

dpnp/tests/third_party/cupy/core_tests/test_core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
from __future__ import annotations
22

33
import sys
4-
import unittest
54

65
import numpy
76
import pytest
87

98
import dpnp as cupy
9+
10+
# from cupy._core import core
1011
from dpnp.tests.third_party.cupy import testing
1112
from dpnp.tests.third_party.cupy.testing._protocol_helpers import (
1213
DummyObjectWithCudaArrayInterface,
1314
DummyObjectWithCuPyGetNDArray,
1415
)
1516

17+
# from cupy_tests.core_tests import test_raw
18+
1619

17-
class TestSize(unittest.TestCase):
20+
class TestSize:
1821

1922
# def tearDown(self):
2023
# # Free huge memory for slow test
@@ -58,7 +61,7 @@ def test_size_huge(self, xp):
5861

5962

6063
@pytest.mark.skip("no cupy._core submodule")
61-
class TestOrder(unittest.TestCase):
64+
class TestOrder:
6265

6366
@testing.for_orders(_orders.keys())
6467
def test_ndarray(self, order):
Lines changed: 72 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
import math
2-
import unittest
1+
from __future__ import annotations
32

43
import numpy
54
import pytest
65

76
# from cupy._core import internal
8-
from dpnp.tests.third_party.cupy import testing
97

108
pytest.skip(
119
"CuPy internal functions are not supported", allow_module_level=True
1210
)
1311

1412

15-
class TestProd(unittest.TestCase):
13+
class TestProd:
1614

1715
def test_empty(self):
1816
assert internal.prod([]) == 1
@@ -24,7 +22,7 @@ def test_two(self):
2422
assert internal.prod([2, 3]) == 6
2523

2624

27-
class TestProdSequence(unittest.TestCase):
25+
class TestProdSequence:
2826

2927
def test_empty(self):
3028
assert internal.prod_sequence(()) == 1
@@ -74,7 +72,7 @@ def test_float(self):
7472
assert internal.get_size(1.0) == (1.0,)
7573

7674

77-
class TestVectorEqual(unittest.TestCase):
75+
class TestVectorEqual:
7876

7977
def test_empty(self):
8078
assert internal.vector_equal([], []) is True
@@ -89,7 +87,7 @@ def test_different_size(self):
8987
assert internal.vector_equal([1, 2, 3], [1, 2]) is False
9088

9189

92-
class TestGetCContiguity(unittest.TestCase):
90+
class TestGetCContiguity:
9391

9492
def test_zero_in_shape(self):
9593
assert internal.get_c_contiguity((1, 0, 1), (1, 1, 1), 3)
@@ -122,134 +120,101 @@ def test_no_contiguous3(self):
122120
assert not internal.get_c_contiguity((3, 1, 3), (6, 6, 4), 2)
123121

124122

125-
class TestInferUnknownDimension(unittest.TestCase):
123+
class TestInferUnknownDimension:
126124

127125
def test_known_all(self):
128126
assert internal.infer_unknown_dimension((1, 2, 3), 6) == [1, 2, 3]
129127

130128
def test_multiple_unknown(self):
131-
with self.assertRaises(ValueError):
129+
with pytest.raises(ValueError):
132130
internal.infer_unknown_dimension((-1, 1, -1), 10)
133131

134132
def test_infer(self):
135133
assert internal.infer_unknown_dimension((-1, 2, 3), 12) == [2, 2, 3]
136134

137135

138-
@testing.parameterize(
139-
{"slice": (2, 8, 1), "expect": (2, 8, 1)},
140-
{"slice": (2, None, 1), "expect": (2, 10, 1)},
141-
{"slice": (2, 1, 1), "expect": (2, 2, 1)},
142-
{"slice": (2, -1, 1), "expect": (2, 9, 1)},
143-
{"slice": (None, 8, 1), "expect": (0, 8, 1)},
144-
{"slice": (-3, 8, 1), "expect": (7, 8, 1)},
145-
{"slice": (11, 8, 1), "expect": (10, 10, 1)},
146-
{"slice": (11, 11, 1), "expect": (10, 10, 1)},
147-
{"slice": (-11, 8, 1), "expect": (0, 8, 1)},
148-
{"slice": (-11, -11, 1), "expect": (0, 0, 1)},
149-
{"slice": (8, 2, -1), "expect": (8, 2, -1)},
150-
{"slice": (8, None, -1), "expect": (8, -1, -1)},
151-
{"slice": (8, 9, -1), "expect": (8, 8, -1)},
152-
{"slice": (8, -3, -1), "expect": (8, 7, -1)},
153-
{"slice": (None, 8, -1), "expect": (9, 8, -1)},
154-
{"slice": (-3, 6, -1), "expect": (7, 6, -1)},
155-
{"slice": (10, 10, -1), "expect": (9, 9, -1)},
156-
{"slice": (10, 8, -1), "expect": (9, 8, -1)},
157-
{"slice": (9, 10, -1), "expect": (9, 9, -1)},
158-
{"slice": (9, 9, -1), "expect": (9, 9, -1)},
159-
{"slice": (9, 8, -1), "expect": (9, 8, -1)},
160-
{"slice": (8, 8, -1), "expect": (8, 8, -1)},
161-
{"slice": (-9, -8, -1), "expect": (1, 1, -1)},
162-
{"slice": (-9, -9, -1), "expect": (1, 1, -1)},
163-
{"slice": (-9, -10, -1), "expect": (1, 0, -1)},
164-
{"slice": (-9, -11, -1), "expect": (1, -1, -1)},
165-
{"slice": (-9, -12, -1), "expect": (1, -1, -1)},
166-
{"slice": (-10, -9, -1), "expect": (0, 0, -1)},
167-
{"slice": (-10, -10, -1), "expect": (0, 0, -1)},
168-
{"slice": (-10, -11, -1), "expect": (0, -1, -1)},
169-
{"slice": (-10, -12, -1), "expect": (0, -1, -1)},
170-
{"slice": (-11, 8, -1), "expect": (-1, -1, -1)},
171-
{"slice": (-11, -9, -1), "expect": (-1, -1, -1)},
172-
{"slice": (-11, -10, -1), "expect": (-1, -1, -1)},
173-
{"slice": (-11, -11, -1), "expect": (-1, -1, -1)},
174-
{"slice": (-11, -12, -1), "expect": (-1, -1, -1)},
136+
@pytest.mark.parametrize(
137+
("slice_", "expect"),
138+
[
139+
((2, 8, 1), (2, 8, 1)),
140+
((2, None, 1), (2, 10, 1)),
141+
((2, 1, 1), (2, 2, 1)),
142+
((2, -1, 1), (2, 9, 1)),
143+
((None, 8, 1), (0, 8, 1)),
144+
((-3, 8, 1), (7, 8, 1)),
145+
((11, 8, 1), (10, 10, 1)),
146+
((11, 11, 1), (10, 10, 1)),
147+
((-11, 8, 1), (0, 8, 1)),
148+
((-11, -11, 1), (0, 0, 1)),
149+
((8, 2, -1), (8, 2, -1)),
150+
((8, None, -1), (8, -1, -1)),
151+
((8, 9, -1), (8, 8, -1)),
152+
((8, -3, -1), (8, 7, -1)),
153+
((None, 8, -1), (9, 8, -1)),
154+
((-3, 6, -1), (7, 6, -1)),
155+
((10, 10, -1), (9, 9, -1)),
156+
((10, 8, -1), (9, 8, -1)),
157+
((9, 10, -1), (9, 9, -1)),
158+
((9, 9, -1), (9, 9, -1)),
159+
((9, 8, -1), (9, 8, -1)),
160+
((8, 8, -1), (8, 8, -1)),
161+
((-9, -8, -1), (1, 1, -1)),
162+
((-9, -9, -1), (1, 1, -1)),
163+
((-9, -10, -1), (1, 0, -1)),
164+
((-9, -11, -1), (1, -1, -1)),
165+
((-9, -12, -1), (1, -1, -1)),
166+
((-10, -9, -1), (0, 0, -1)),
167+
((-10, -10, -1), (0, 0, -1)),
168+
((-10, -11, -1), (0, -1, -1)),
169+
((-10, -12, -1), (0, -1, -1)),
170+
((-11, 8, -1), (-1, -1, -1)),
171+
((-11, -9, -1), (-1, -1, -1)),
172+
((-11, -10, -1), (-1, -1, -1)),
173+
((-11, -11, -1), (-1, -1, -1)),
174+
((-11, -12, -1), (-1, -1, -1)),
175+
],
175176
)
176-
class TestCompleteSlice(unittest.TestCase):
177+
def test_complete_slice(slice_, expect):
178+
assert internal.complete_slice(slice(*slice_), 10) == slice(*expect)
177179

178-
def test_complete_slice(self):
179-
assert internal.complete_slice(slice(*self.slice), 10) == slice(
180-
*self.expect
181-
)
182180

183-
184-
class TestCompleteSliceError(unittest.TestCase):
181+
class TestCompleteSliceError:
185182

186183
def test_invalid_step_value(self):
187-
with self.assertRaises(ValueError):
184+
with pytest.raises(ValueError):
188185
internal.complete_slice(slice(1, 1, 0), 1)
189186

190187
def test_invalid_step_type(self):
191-
with self.assertRaises(TypeError):
188+
with pytest.raises(TypeError):
192189
internal.complete_slice(slice(1, 1, (1, 2)), 1)
193190

194191
def test_invalid_start_type(self):
195-
with self.assertRaises(TypeError):
192+
with pytest.raises(TypeError):
196193
internal.complete_slice(slice((1, 2), 1, 1), 1)
197-
with self.assertRaises(TypeError):
194+
with pytest.raises(TypeError):
198195
internal.complete_slice(slice((1, 2), 1, -1), 1)
199196

200197
def test_invalid_stop_type(self):
201-
with self.assertRaises(TypeError):
198+
with pytest.raises(TypeError):
202199
internal.complete_slice(slice((1, 2), 1, 1), 1)
203-
with self.assertRaises(TypeError):
200+
with pytest.raises(TypeError):
204201
internal.complete_slice(slice((1, 2), 1, -1), 1)
205202

206203

207-
@testing.parameterize(
208-
{"x": 0, "expect": 0},
209-
{"x": 1, "expect": 1},
210-
{"x": 2, "expect": 2},
211-
{"x": 3, "expect": 4},
212-
{"x": 2**10, "expect": 2**10},
213-
{"x": 2**10 - 1, "expect": 2**10},
214-
{"x": 2**10 + 1, "expect": 2**11},
215-
{"x": 2**40, "expect": 2**40},
216-
{"x": 2**40 - 1, "expect": 2**40},
217-
{"x": 2**40 + 1, "expect": 2**41},
204+
@pytest.mark.parametrize(
205+
("x", "expect"),
206+
[
207+
(0, 0),
208+
(1, 1),
209+
(2, 2),
210+
(3, 4),
211+
(2**10, 2**10),
212+
(2**10 - 1, 2**10),
213+
(2**10 + 1, 2**11),
214+
(2**40, 2**40),
215+
(2**40 - 1, 2**40),
216+
(2**40 + 1, 2**41),
217+
],
218218
)
219-
class TestClp2(unittest.TestCase):
220-
221-
def test_clp2(self):
222-
assert internal.clp2(self.x) == self.expect
223-
224-
225-
@testing.parameterize(
226-
*testing.product(
227-
{
228-
"value": [
229-
0.0,
230-
1.0,
231-
-1.0,
232-
0.25,
233-
-0.25,
234-
11.0,
235-
-11.0,
236-
2**-15,
237-
-(2**-15), # Denormalized Number
238-
float("inf"),
239-
float("-inf"),
240-
],
241-
}
242-
)
243-
)
244-
class TestConvertFloat16(unittest.TestCase):
245-
246-
def test_conversion(self):
247-
half = internal.to_float16(self.value)
248-
assert internal.from_float16(half) == self.value
249-
250-
251-
class TestConvertFloat16Nan(unittest.TestCase):
252-
253-
def test_conversion(self):
254-
half = internal.to_float16(float("nan"))
255-
assert math.isnan(internal.from_float16(half))
219+
def test_clp2(x, expect):
220+
assert internal.clp2(x) == expect

0 commit comments

Comments
 (0)