Skip to content

Commit 5657d01

Browse files
committed
TEST/RF: Reparametrize tests
1 parent a98b023 commit 5657d01

File tree

2 files changed

+25
-38
lines changed

2 files changed

+25
-38
lines changed

nibabel/tests/test_scaling.py

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,31 +157,25 @@ def test_array_file_scales(in_type, out_type):
157157
assert np.all(np.abs(arr - arr3) <= max_miss)
158158

159159

160-
@pytest.mark.parametrize("in_type, out_type",[
161-
('int', 'int'),
162-
('uint', 'int'),
163-
])
164-
def test_scaling_in_abstract(in_type, out_type):
160+
@pytest.mark.parametrize("category0, category1, overflow",[
165161
# Confirm that, for all ints and uints as input, and all possible outputs,
166162
# for any simple way of doing the calculation, the result is near enough
167-
for in_tp in np.sctypes[in_type]:
168-
for out_tp in np.sctypes[out_type]:
169-
check_int_a2f(in_tp, out_tp)
170-
171-
172-
@pytest.mark.parametrize("in_type, out_type", [
173-
('float', 'int'),
174-
('float', 'uint'),
175-
('complex', 'int'),
176-
('complex', 'uint'),
177-
])
178-
def test_scaling_in_abstract_warn(in_type, out_type):
179-
163+
('int', 'int', False),
164+
('uint', 'int', False),
180165
# Converting floats to integer
181-
for in_tp in np.sctypes[in_type]:
182-
for out_tp in np.sctypes[out_type]:
183-
with suppress_warnings(): # overflow
184-
check_int_a2f(in_tp, out_tp)
166+
('float', 'int', True),
167+
('float', 'uint', True),
168+
('complex', 'int', True),
169+
('complex', 'uint', True),
170+
])
171+
def test_scaling_in_abstract(category0, category1, overflow):
172+
for in_type in np.sctypes[category0]:
173+
for out_type in np.sctypes[category1]:
174+
if overflow:
175+
with suppress_warnings():
176+
check_int_a2f(in_type, out_type)
177+
else:
178+
check_int_a2f(in_type, out_type)
185179

186180

187181
def check_int_a2f(in_type, out_type):

nibabel/tests/test_testing.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,31 +136,24 @@ def f():
136136
with pytest.raises(ValueError):
137137
f()
138138

139-
@pytest.mark.parametrize("args", [
139+
@pytest.mark.parametrize("regex, entries", [
140140
[".*", ""],
141141
[".*", ["any"]],
142142
["ab", "abc"],
143143
# Sufficient to have one entry matching
144144
["ab", ["", "abc", "laskdjf"]],
145145
# Tuples should be ok too
146-
["ab", ("", "abc", "laskdjf")]
147-
])
148-
def test_assert_re_in(args):
149-
assert_re_in(*args)
150-
151-
152-
@pytest.mark.parametrize("args", [
146+
["ab", ("", "abc", "laskdjf")],
153147
# Should do match not search
154-
["ab", "cab"],
155-
["ab$", "abc"],
156-
["ab$", ["ddd", ""]],
157-
["ab$", ("ddd", "")],
148+
pytest.param("ab", "cab", marks=pytest.mark.xfail),
149+
pytest.param("ab$", "abc", marks=pytest.mark.xfail),
150+
pytest.param("ab$", ["ddd", ""], marks=pytest.mark.xfail),
151+
pytest.param("ab$", ("ddd", ""), marks=pytest.mark.xfail),
158152
#Shouldn't "match" the empty list
159-
["", []]
153+
pytest.param("", [], marks=pytest.mark.xfail)
160154
])
161-
def test_assert_re_in_exception(args):
162-
with pytest.raises(AssertionError):
163-
assert_re_in(*args)
155+
def test_assert_re_in(regex, entries):
156+
assert_re_in(regex, entries)
164157

165158

166159
def test_test_data():

0 commit comments

Comments
 (0)