8000 TST: Use pytest for some already-parametrized tests. · eric-wieser/numpy@5900a0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5900a0d

Browse files
committed
TST: Use pytest for some already-parametrized tests.
1 parent df35b3d commit 5900a0d

File tree

1 file changed

+18
-55
lines changed

1 file changed

+18
-55
lines changed

numpy/core/tests/test_multiarray.py

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,15 +4133,12 @@ def test_ip_types(self):
41334133
def test_mask_size(self):
41344134
assert_raises(ValueError, np.putmask, np.array([1, 2, 3]), [True], 5)
41354135

4136-
def tst_byteorder(self, dtype):
4136+
@pytest.mark.parametrize('dtype', ('>i4', '<i4'))
4137+
def test_byteorder(self, dtype):
41374138
x = np.array([1, 2, 3], dtype)
41384139
np.putmask(x, [True, False, True], -1)
41394140
assert_array_equal(x, [-1, 2, -1])
41404141

4141-
def test_ip_byteorder(self):
4142-
for dtype in ('>i4', '<i4'):
4143-
self.tst_byteorder(dtype)
4144-
41454142
def test_record_array(self):
41464143
# Note mixed byteorder.
41474144
rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
@@ -4191,14 +4188,11 @@ def test_wrap(self):
41914188
assert_array_equal(x.take([2], axis=0, mode='wrap')[0], x[0])
41924189
assert_array_equal(x.take([3], axis=0, mode='wrap')[0], x[1])
41934190

4194-
def tst_byteorder(self, dtype):
4191+
@pytest.mark.parametrize('dtype', ('>i4', '<i4'))
4192+
def test_byteorder(self, dtype):
41954193
x = np.array([1, 2, 3], dtype)
41964194
assert_array_equal(x.take([0, 2, 1]), [1, 3, 2])
41974195

4198-
def test_ip_byteorder(self):
4199-
for dtype in ('>i4', '<i4'):
4200-
self.tst_byteorder(dtype)
4201-
42024196
def test_record_array(self):
42034197
# Note mixed byteorder.
42044198
rec = np.array([(-5, 2.0, 3.0), (5.0, 4.0, 3.0)],
@@ -4574,19 +4568,16 @@ def test_locale(self):
45744568

45754569

45764570
class TestFromBuffer(object):
4577-
def tst_basic(self, buffer, expected, kwargs):
4578-
assert_array_equal(np.frombuffer(buffer,**kwargs), expected)
4579-
4580-
def test_ip_basic(self):
4581-
for byteorder in ['<', '>']:
4582-
for dtype in [float, int, complex]:
4583-
dt = np.dtype(dtype).newbyteorder(byteorder)
4584-
x = (np.random.random((4, 7))*5).astype(dt)
4585-
buf = x.tobytes()
4586-
self.tst_basic(buf, x.flat, {'dtype':dt})
4571+
@pytest.mark.parametrize('byteorder', ['<', '>'])
4572+
@pytest.mark.parametrize('dtype', [float, int, complex])
4573+
def test_basic(self, byteorder, dtype):
4574+
dt = np.dtype(dtype).newbyteorder(byteorder)
4575+
x = (np.random.random((4, 7)) * 5).astype(dt)
4576+
buf = x.tobytes()
4577+
assert_array_equal(np.frombuffer(buf, dtype=dt), x.flat)
45874578

45884579
def test_empty(self):
4589-
self.tst_basic(b'', np.array([]), {})
4580+
assert_array_equal(np.frombuffer(b''), np.array([]))
45904581

45914582

45924583
class TestFlat(object):
@@ -5940,9 +5931,10 @@ def test_broadcast2(self):
59405931
NEIGH_MODE = {'zero': 0, 'one': 1, 'constant': 2, 'circular': 3, 'mirror': 4}
59415932

59425933

5934+
@pytest.mark.parametrize('dt', [float, Decimal], ids=['float', 'object'])
59435935
class TestNeighborhoodIter(object):
59445936
# Simple, 2d tests
5945-
def _test_simple2d(self, dt):
5937+
def test_simple2d(self, dt):
59465938
# Test zero and one padding for simple data type
59475939
x = np.array([[0, 1], [2, 3]], dtype=dt)
59485940
r = [np.array([[0, 0, 0], [0, 0, 1]], dtype=dt),
@@ -5969,13 +5961,7 @@ def _test_simple2d(self, dt):
59695961
x, [-1, 0, -1, 1], 4, NEIGH_MODE['constant'])
59705962
assert_array_equal(l, r)
59715963

5972-
def test_simple2d(self):
5973-
self._test_simple2d(float)
5974-
5975-
def test_simple2d_object(self):
5976-
self._test_simple2d(Decimal)
5977-
5978-
def _test_mirror2d(self, dt):
5964+
def test_mirror2d(self, dt):
59795965
x = np.array([[0, 1], [2, 3]], dtype=dt)
59805966
r = [np.array([[0, 0, 1], [0, 0, 1]], dtype=dt),
59815967
np.array([[0, 1, 1], [0, 1, 1]], dtype=dt),
@@ -5985,14 +5971,8 @@ def _test_mirror2d(self, dt):
59855971
x, [-1, 0, -1, 1], x[0], NEIGH_MODE['mirror'])
59865972
assert_array_equal(l, r)
59875973

5988-
def test_mirror2d(self):
5989-
self._test_mirror2d(float)
5990-
5991-
def test_mirror2d_object(self):
5992-
self._test_mirror2d(Decimal)
5993-
59945974
# Simple, 1d tests
5995-
def _test_simple(self, dt):
5975+
def test_simple(self, dt):
59965976
# Test padding with constant values
59975977
x = np.linspace(1, 5, 5).astype(dt)
59985978
r = [[0, 1, 2], [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 0]]
@@ -6010,14 +5990,8 @@ def _test_simple(self, dt):
60105990
x, [-1, 1], x[4], NEIGH_MODE['constant'])
60115991
assert_array_equal(l, r)
60125992

6013-
def test_simple_float(self):
6014-
self._test_simple(float)
6015-
6016-
def test_simple_object(self):
6017-
self._test_simple(Decimal)
6018-
60195993
# Test mirror modes
6020-
def _test_mirror(self, dt):
5994+
def test_mirror(self, dt):
60215995
x = np.linspace(1, 5, 5).astype(dt)
60225996
r = np.array([[2, 1, 1, 2, 3], [1, 1, 2, 3, 4], [1, 2, 3, 4, 5],
60235997
[2, 3, 4, 5, 5], [3, 4, 5, 5, 4]], dtype=dt)
@@ -6026,26 +6000,15 @@ def _test_mirror(self, dt):
60266000
assert_([i.dtype == dt for i in l])
60276001
assert_array_equal(l, r)
60286002

6029-
def test_mirror(self):
6030-
self._test_mirror(float)
6031-
6032-
def test_mirror_object(self):
6033-
self._test_mirror(Decimal)
6034-
60356003
# Circular mode
6036-
def _test_circular(self, dt):
6004+
def test_circular(self, dt):
60376005
x = np.linspace(1, 5, 5).astype(dt)
60386006
r = np.array([[4, 5, 1, 2, 3], [5, 1, 2, 3, 4], [1, 2, 3, 4, 5],
60396007
[2, 3, 4, 5, 1], [3, 4, 5, 1, 2]], dtype=dt)
60406008
l = _multiarray_tests.test_neighborhood_iterator(
60416009
x, [-2, 2], x[0], NEIGH_MODE['circular'])
60426010
assert_array_equal(l, r)
60436011

6044-
def test_circular(self):
6045-
self._test_circular(float)
6046-
6047-
def test_circular_object(self):
6048-
self._test_circular(Decimal)
60496012

60506013
# Test stacking neighborhood iterators
60516014
class TestStackedNeighborhoodIter(object):

0 commit comments

Comments
 (0)
0