10000 Merge pull request #10294 from xoviat/pytest-cleanup · numpy/numpy@3d2205d · GitHub
[go: up one dir, main page]

Skip to content

Commit 3d2205d

Browse files
authored
Merge pull request #10294 from xoviat/pytest-cleanup
MAINT: pytest cleanups
2 parents 6540a7b + dbc143b commit 3d2205d

File tree

6 files changed

+51
-58
lines changed

6 files changed

+51
-58
lines changed

numpy/core/tests/test_mem_overlap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def test_overlapping_assignments():
9494
srcidx = tuple([a[0] for a in ind])
9595
dstidx = tuple([a[1] for a in ind])
9696

97-
yield _check_assignment, srcidx, dstidx
97+
_check_assignment(srcidx, dstidx)
9898

9999

100100
@dec.slow

numpy/core/tests/test_print.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_float_types():
4040
4141
"""
4242
for t in [np.float32, np.double, np.longdouble]:
43-
yield check_float_type, t
43+
check_float_type(t)
4444

4545
def check_nan_inf_float(tp):
4646
for x in [np.inf, -np.inf, np.nan]:
@@ -56,7 +56,7 @@ def test_nan_inf_float():
5656
5757
"""
5858
for t in [np.float32, np.double, np.longdouble]:
59-
yield check_nan_inf_float, t
59+
check_nan_inf_float(t)
6060

6161
def check_complex_type(tp):
6262
for x in [0, 1, -1, 1e20]:
@@ -84,7 +84,7 @@ def test_complex_types():
8484
8585
"""
8686
for t in [np.complex64, np.cdouble, np.clongdouble]:
87-
yield check_complex_type, t
87+
check_complex_type(t)
8888

8989
def test_complex_inf_nan():
9090
"""Check inf/nan formatting of complex types."""
@@ -108,7 +108,7 @@ def test_complex_inf_nan():
108108
}
109109
for tp in [np.complex64, np.cdouble, np.clongdouble]:
110110
for c, s in TESTS.items():
111-
yield _check_complex_inf_nan, c, s, tp
111+
_check_complex_inf_nan(c, s, tp)
< 9E81 /code>
112112

113113
def _check_complex_inf_nan(c, s, dtype):
114114
assert_equal(str(dtype(c)), s)
@@ -164,12 +164,12 @@ def check_complex_type_print(tp):
164164
def test_float_type_print():
165165
"""Check formatting when using print """
166166
for t in [np.float32, np.double, np.longdouble]:
167-
yield check_float_type_print, t
167+
check_float_type_print(t)
168168

169169
def test_complex_type_print():
170170
"""Check formatting when using print """
171171
for t in [np.complex64, np.cdouble, np.clongdouble]:
172-
yield check_complex_type_print, t
172+
check_complex_type_print(t)
173173

174174
def test_scalar_format():
175175
"""Test the str.format method with NumPy scalar types"""

numpy/core/tests/test_scalarmath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def test_float_repr(self):
538538
# long double test cannot work, because eval goes through a python
539539
# float
540540
for t in [np.float32, np.float64]:
541-
yield self._test_type_repr, t
541+
self._test_type_repr(t)
542542

543543

544544
if not IS_PYPY:

numpy/core/tests/test_umath.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,53 +2335,53 @@ def test_precisions_consistent(self):
23352335

23362336
def test_branch_cuts(self):
23372337
# check branch cuts and continuity on them
2338-
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True
2339-
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True
2340-
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
2341-
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
2342-
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True
2338+
_check_branch_cut(np.log, -0.5, 1j, 1, -1, True)
2339+
_check_branch_cut(np.log2, -0.5, 1j, 1, -1, True)
2340+
_check_branch_cut(np.log10, -0.5, 1j, 1, -1, True)
2341+
_check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True)
2342+
_check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True)
23432343

2344-
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True
2345-
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True
2346-
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True
2344+
_check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True)
2345+
_check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True)
2346+
_check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True)
23472347

2348-
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True
2349-
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True
2350-
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True
2348+
_check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True)
2349+
_check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True)
2350+
_check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True)
23512351

23522352
# check against bogus branch cuts: assert continuity between quadrants
2353-
yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1
2354-
yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1
2355-
yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1
2353+
_check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1)
2354+
_check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1)
2355+
_check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1)
23562356

2357-
yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1
2358-
yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1
2359-
yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1
2357+
_check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1)
2358+
_check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1)
2359+
_check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1)
23602360

23612361
def test_branch_cuts_complex64(self):
23622362
# check branch cuts and continuity on them
2363-
yield _check_branch_cut, np.log, -0.5, 1j, 1, -1, True, np.complex64
2364-
yield _check_branch_cut, np.log2, -0.5, 1j, 1, -1, True, np.complex64
2365-
yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
2366-
yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
2367-
yield _check_branch_cut, np.sqrt, -0.5, 1j, 1, -1, True, np.complex64
2363+
_check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64< F987 span class="x x-first x-last">)
2364+
_check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64)
2365+
_check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64)
2366+
_check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64)
2367+
_check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64)
23682368

2369-
yield _check_branch_cut, np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
2370-
yield _check_branch_cut, np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
2371-
yield _check_branch_cut, np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64
2369+
_check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64)
2370+
_check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64)
2371+
_check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64)
23722372

2373-
yield _check_branch_cut, np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64
2374-
yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64
2375-
yield _check_branch_cut, np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64
2373+
_check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64)
2374+
_check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64)
2375+
_check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64)
23762376

23772377
# check against bogus branch cuts: assert continuity between quadrants
2378-
yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64
2379-
yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64
2380-
yield _check_branch_cut, np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64
2378+
_check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64)
2379+
_check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64)
2380+
_check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64)
23812381

2382-
yield _check_branch_cut, np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
2383-
yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64
2384-
yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64
2382+
_check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64)
2383+
_check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64)
2384+
_check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
23852385

23862386
def test_against_cmath(self):
23872387
import cmath
@@ -2489,7 +2489,7 @@ def check(func, z0, d=1):
24892489

24902490
def test_loss_of_precision(self):
24912491
for dtype in [np.complex64, np.complex_]:
2492-
yield self.check_loss_of_precision, dtype
2492+
self.check_loss_of_precision(dtype)
24932493

24942494
@dec.knownfailureif(is_longdouble_finfo_bogus(), "Bogus long double finfo")
24952495
def test_loss_of_precision_longcomplex(self):

numpy/lib/tests/test_format.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,20 @@ def assert_equal_(o1, o2):
454454
def test_roundtrip():
455455
for arr in basic_arrays + record_arrays:
456456
arr2 = roundtrip(arr)
457-
yield assert_array_equal, arr, arr2
457+
assert_array_equal(arr, arr2)
458458

459459

460460
def test_roundtrip_randsize():
461461
for arr in basic_arrays + record_arrays:
462462
if arr.dtype != object:
463463
arr2 = roundtrip_randsize(arr)
464-
yield assert_array_equal, arr, arr2
464+
assert_array_equal(arr, arr2)
465465

466466

467467
def test_roundtrip_truncated():
468468
for arr in basic_arrays:
469469
if arr.dtype != object:
470-
yield assert_raises, ValueError, roundtrip_truncated, arr
470+
assert_raises(ValueError, roundtrip_truncated, arr)
471471

472472

473473
def test_long_str():
@@ -508,7 +508,7 @@ def test_memmap_roundtrip():
508508
fp = open(mfn, 'rb')
509509
memmap_bytes = fp.read()
510510
fp.close()
511-
yield assert_equal_, normal_bytes, memmap_bytes
511+
assert_equal_(normal_bytes, memmap_bytes)
512512

513513
# Check that reading the file using memmap works.
514514
ma = format.open_memmap(nfn, mode='r')
@@ -728,13 +728,13 @@ def test_read_magic():
728728
def test_read_magic_bad_magic():
729729
for magic in malformed_magic:
730730
f = BytesIO(magic)
731-
yield raises(ValueError)(format.read_magic), f
731+
assert_raises(ValueError, format.read_array, f)
732732

733733

734734
def test_read_version_1_0_bad_magic():
735735
for magic in bad_version_magic + malformed_magic:
736736
f = BytesIO(magic)
737-
yield raises(ValueError)(format.read_array), f
737+
assert_raises(ValueError, format.read_array, f)
738738

739739

740740
def test_bad_magic_args():

numpy/testing/pytest_tools/utils.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,16 +1219,9 @@ def assert_raises(exception_class, fn=None, *args, **kwargs):
12191219
if fn is not None:
12201220
pytest.raises(exception_class, fn, *args,**kwargs)
12211221
else:
1222-
@contextlib.contextmanager
1223-
def assert_raises_context():
1224-
try:
1225-
yield
1226-
except BaseException as raised_exception:
1227-
assert isinstance(raised_exception, exception_class)
1228-
else:
1229-
raise ValueError('Function did not raise an exception')
1222+
assert not kwargs
12301223

1231-
return assert_raises_context()
1224+
return pytest.raises(exception_class)
12321225

12331226

12341227
def assert_raises_regex(exception_class, expected_regexp, *args, **kwargs):

0 commit comments

Comments
 (0)
0