8000 Use pytest contexts in test_preprocess_data.py. · matplotlib/matplotlib@7f0ea4a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7f0ea4a

Browse files
committed
Use pytest contexts in test_preprocess_data.py.
1 parent 6d979db commit 7f0ea4a

File tree

1 file changed

+12
-31
lines changed

1 file changed

+12
-31
lines changed

lib/matplotlib/tests/test_preprocess_data.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import re
44

55
import pytest
6-
from nose.tools import assert_raises
7-
8-
from ..testing import assert_produces_warning
96

107
from .. import _preprocess_data
118

@@ -58,33 +55,26 @@ def func_no_ax_args(*args, **kwargs): pass
5855
_preprocess_data(replace_names=["x", "y"])(func_args)
5956

6057
# no positional_parameter_names but needed due to replaces
61-
def f():
58+
with pytest.raises(AssertionError):
6259
# z is unknown
6360
_preprocess_data(replace_names=["x", "y", "z"])(func_args)
6461

65-
assert_raises(AssertionError, f)
66-
67-
def f():
62+
with pytest.raises(AssertionError):
6863
_preprocess_data(replace_names=["x", "y"])(func_no_ax_args)
6964

70-
assert_raises(AssertionError, f)
71-
7265
# no replacements at all -> all ok...
7366
_preprocess_data(replace_names=[], label_namer=None)(func)
7467
_preprocess_data(replace_names=[], label_namer=None)(func_args)
7568
_preprocess_data(replace_names=[], label_namer=None)(func_kwargs)
7669
_preprocess_data(replace_names=[], label_namer=None)(func_no_ax_args)
7770

7871
# label namer is unknown
79-
def f():
72+
with pytest.raises(AssertionError):
8073
_preprocess_data(label_namer="z")(func)
8174

82-
assert_raises(AssertionError, f)
83-
84-
def f():
75+
with pytest.raises(AssertionError):
8576
_preprocess_data(label_namer="z")(func_args)
8677

87-
assert_raises(AssertionError, f)
8878
# but "ok-ish", if func has kwargs -> will show up at runtime :-(
8979
_preprocess_data(label_namer="z")(func_kwargs)
9080
_preprocess_data(label_namer="z")(func_no_ax_args)
@@ -97,15 +87,12 @@ def test_label_problems_at_runtime():
9787
def func(*args, **kwargs):
9888
pass
9989

100-
def f():
101-
func(None, x="a", y="b")
102-
10390
# This is a programming mistake: the parameter which should add the
10491
# label is not present in the function call. Unfortunately this was masked
10592
# due to the **kwargs useage
10693
# This would be nice to handle as a compiletime check (see above...)
107-
with assert_produces_warning(RuntimeWarning):
108-
f()
94+
with pytest.warns(RuntimeWarning):
95+
func(None, x="a", y="b")
10996

11097
def real_func(x, y):
11198
pass
@@ -114,11 +101,9 @@ def real_func(x, y):
114101
def func(*args, **kwargs):
115102
real_func(**kwargs)
116103

117-
def f():
118-
func(None, x="a", y="b")
119-
120104
# This sets a label although the function can't handle it.
121-
assert_raises(TypeError, f)
105+
with pytest.raises(TypeError):
106+
func(None, x="a", y="b")
122107

123108

124109
def test_function_call_without_data():
@@ -252,7 +237,7 @@ def func_varags_replace_all(ax, *args, **kwargs):
252237
data=data) ==
253238
"x: [1, 2], y: [8, 9], ls: x, w: xyz, label: text")
254239

255-
with assert_produces_warning():
240+
with pytest.warns(RuntimeWarning):
256241
assert (func_varags_replace_all(None, "a", "b", w="x", data=data) ==
257242
"x: [1, 2], y: [8, 9], ls: x, w: xyz, label: None")
258243

@@ -282,12 +267,9 @@ def func(ax, x, y, z=1):
282267
pass
283268

284269
data = {"a": [1, 2], "b": [8, 9], "w": "NOT"}
285-
286-
def f():
270+
with pytest.raises(RuntimeError):
287271
func(None, "a", "b", "z", "z", data=data)
288272

289-
assert_raises(RuntimeError, f)
290-
291273

292274
def test_function_call_with_replace_all_args():
293275
"""Test with a "replace_all_args" argument, all *args should be replaced"""
@@ -392,13 +374,12 @@ def funcy(ax, *args, **kwargs):
392374
assert funcy(None, "x", "hy1", "c", data=data) == "('X', 'Y', 'c') | {}"
393375

394376
# no arbitrary long args with data
395-
def f():
377+
with pytest.raises(ValueError):
396378
assert (funcy(None, "x", "y", "c", "x", "y", "x", "y", data=data) ==
397379
"('X', 'Y', 'c', 'X', 'Y', 'X', 'Y') | {}")
398-
assert_raises(ValueError, f)
399380

400381
# In the two arg case, if a valid color spec is in data, we warn but use
401382
# it as data...
402383
data = {"x": "X", "y": "Y", "ro": "!!"}
403-
with assert_produces_warning(RuntimeWarning):
384+
with pytest.warns(RuntimeWarning):
404385
assert funcy(None, "y", "ro", data=data) == "('Y', '!!') | {}"

0 commit comments

Comments
 (0)
0