3
3
import re
4
4
5
5
import pytest
6
- from nose .tools import assert_raises
7
-
8
- from ..testing import assert_produces_warning
9
6
10
7
from .. import _preprocess_data
11
8
@@ -58,33 +55,26 @@ def func_no_ax_args(*args, **kwargs): pass
58
55
_preprocess_data (replace_names = ["x" , "y" ])(func_args )
59
56
60
57
# no positional_parameter_names but needed due to replaces
61
- def f ( ):
58
+ with pytest . raises ( AssertionError ):
62
59
# z is unknown
63
60
_preprocess_data (replace_names = ["x" , "y" , "z" ])(func_args )
64
61
65
- assert_raises (AssertionError , f )
66
-
67
- def f ():
62
+ with pytest .raises (AssertionError ):
68
63
_preprocess_data (replace_names = ["x" , "y" ])(func_no_ax_args )
69
64
70
- assert_raises (AssertionError , f )
71
-
72
65
# no replacements at all -> all ok...
73
66
_preprocess_data (replace_names = [], label_namer = None )(func )
74
67
_preprocess_data (replace_names = [], label_namer = None )(func_args )
75
68
_preprocess_data (replace_names = [], label_namer = None )(func_kwargs )
76
69
_preprocess_data (replace_names = [], label_namer = None )(func_no_ax_args )
77
70
78
71
# label namer is unknown
79
- def f ( ):
72
+ with pytest . raises ( AssertionError ):
80
73
_preprocess_data (label_namer = "z" )(func )
81
74
82
- assert_raises (AssertionError , f )
83
-
84
- def f ():
75
+ with pytest .raises (AssertionError ):
85
76
_preprocess_data (label_namer = "z" )(func_args )
86
77
87
- assert_raises (AssertionError , f )
88
78
# but "ok-ish", if func has kwargs -> will show up at runtime :-(
89
79
_preprocess_data (label_namer = "z" )(func_kwargs )
90
80
_preprocess_data (label_namer = "z" )(func_no_ax_args )
@@ -97,15 +87,12 @@ def test_label_problems_at_runtime():
97
87
def func (* args , ** kwargs ):
98
88
pass
99
89
100
- def f ():
101
- func (None , x = "a" , y = "b" )
102
-
103
90
# This is a programming mistake: the parameter which should add the
104
91
# label is not present in the function call. Unfortunately this was masked
105
92
# due to the **kwargs useage
106
93
# 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" )
109
96
110
97
def real_func (x , y ):
111
98
pass
@@ -114,11 +101,9 @@ def real_func(x, y):
114
101
def func (* args , ** kwargs ):
115
102
real_func (** kwargs )
116
103
117
- def f ():
118
- func (None , x = "a" , y = "b" )
119
-
120
104
# 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" )
122
107
123
108
124
109
def test_function_call_without_data ():
@@ -252,7 +237,7 @@ def func_varags_replace_all(ax, *args, **kwargs):
252
237
data = data ) ==
253
238
"x: [1, 2], y: [8, 9], ls: x, w: xyz, label: text" )
254
239
255
- with assert_produces_warning ( ):
240
+ with pytest . warns ( RuntimeWarning ):
256
241
assert (func_varags_replace_all (None , "a" , "b" , w = "x" , data = data ) ==
257
242
"x: [1, 2], y: [8, 9], ls: x, w: xyz, label: None" )
258
243
@@ -282,12 +267,9 @@ def func(ax, x, y, z=1):
282
267
pass
283
268
284
269
data = {"a" : [1 , 2 ], "b" : [8 , 9 ], "w" : "NOT" }
285
-
286
- def f ():
270
+ with pytest .raises (RuntimeError ):
287
271
func (None , "a" , "b" , "z" , "z" , data = data )
288
272
289
- assert_raises (RuntimeError , f )
290
-
291
273
292
274
def test_function_call_with_replace_all_args ():
293
275
"""Test with a "replace_all_args" argument, all *args should be replaced"""
@@ -392,13 +374,12 @@ def funcy(ax, *args, **kwargs):
392
374
assert funcy (None , "x" , "hy1" , "c" , data = data ) == "('X', 'Y', 'c') | {}"
393
375
394
376
# no arbitrary long args with data
395
- def f ( ):
377
+ with pytest . raises ( ValueError ):
396
378
assert (funcy (None , "x" , "y" , "c" , "x" , "y" , "x" , "y" , data = data ) ==
397
379
"('X', 'Y', 'c', 'X', 'Y', 'X', 'Y') | {}" )
398
- assert_raises (ValueError , f )
399
380
400
381
# In the two arg case, if a valid color spec is in data, we warn but use
401
382
# it as data...
402
383
data = {"x" : "X" , "y" : "Y" , "ro" : "!!" }
403
- with assert_produces_warning (RuntimeWarning ):
384
+ with pytest . warns (RuntimeWarning ):
404
385
assert funcy (None , "y" , "ro" , data = data ) == "('Y', '!!') | {}"
0 commit comments