|
12 | 12 | frommatplotlib.testing.decoratorsimportimage_comparison,check_figures_equal
|
13 | 13 |
|
14 | 14 |
|
15 |
| -x= [-1,0,1,0] |
16 |
| -y= [0,-1,0,1] |
17 |
| -triangles= [[0,1,2], [0,2,3]] |
18 |
| -mask= [False,True] |
19 |
| - |
20 |
| - |
21 |
| -@pytest.mark.parametrize('args, kwargs, expected', [ |
22 |
| - ([x,y], {}, [x,y,None,None]), |
23 |
| - ([x,y,triangles], {}, [x,y,triangles,None]), |
24 |
| - ([x,y],dict(triangles=triangles), [x,y,triangles,None]), |
25 |
| - ([x,y],dict(mask=mask), [x,y,None,mask]), |
26 |
| - ([x,y,triangles],dict(mask=mask), [x,y,triangles,mask]), |
27 |
| - ([x,y],dict(triangles=triangles,mask=mask), [x,y,triangles,mask]), |
28 |
| -]) |
29 |
| -deftest_extract_triangulation_params(args,kwargs,expected): |
30 |
| -other_args= [1,2] |
31 |
| -other_kwargs= {'a':3,'b':'4'} |
32 |
| -x_,y_,triangles_,mask_,args_,kwargs_= \ |
33 |
| -mtri.Triangulation._extract_triangulation_params( |
34 |
| -args+other_args, {**kwargs,**other_kwargs}) |
35 |
| -x,y,triangles,mask=expected |
36 |
| -assertx_isx |
37 |
| -asserty_isy |
38 |
| -assert_array_equal(triangles_,triangles) |
39 |
| -assertmask_ismask |
40 |
| -assertargs_==other_args |
41 |
| -assertkwargs_==other_kwargs |
| 15 | +classTestTriangulationParams: |
| 16 | +x= [-1,0,1,0] |
| 17 | +y= [0,-1,0,1] |
| 18 | +triangles= [[0,1,2], [0,2,3]] |
| 19 | +mask= [False,True] |
| 20 | + |
| 21 | +@pytest.mark.parametrize('args, kwargs, expected', [ |
| 22 | +([x,y], {}, [x,y,None,None]), |
| 23 | +([x,y,triangles], {}, [x,y,triangles,None]), |
| 24 | +([x,y],dict(triangles=triangles), [x,y,triangles,None]), |
| 25 | +([x,y],dict(mask=mask), [x,y,None,mask]), |
| 26 | +([x,y,triangles],dict(mask=mask), [x,y,triangles,mask]), |
| 27 | +([x,y],dict(triangles=triangles,mask=mask), [x,y,triangles,mask]), |
| 28 | +]) |
| 29 | +deftest_extract_triangulation_params(self,args,kwargs,expected): |
| 30 | +other_args= [1,2] |
| 31 | +other_kwargs= {'a':3,'b':'4'} |
| 32 | +x_,y_,triangles_,mask_,args_,kwargs_= \ |
| 33 | +mtri.Triangulation._extract_triangulation_params( |
| 34 | +args+other_args, {**kwargs,**other_kwargs}) |
| 35 | +x,y,triangles,mask=expected |
| 36 | +assertx_isx |
| 37 | +asserty_isy |
| 38 | +assert_array_equal(triangles_,triangles) |
| 39 | +assertmask_ismask |
| 40 | +assertargs_==other_args |
| 41 | +assertkwargs_==other_kwargs |
42 | 42 |
|
43 | 43 |
|
44 | 44 | deftest_extract_triangulation_positional_mask():
|
45 |
| -globalx,y,triangles,mask |
46 | 45 | # mask cannot be passed positionally
|
| 46 | +mask= [True] |
| 47 | +args= [[0,2,1], [0,0,1], [[0,1,2]],mask] |
47 | 48 | x_,y_,triangles_,mask_,args_,kwargs_= \
|
48 |
| -mtri.Triangulation._extract_triangulation_params(x,y,triangles,mask) |
| 49 | +mtri.Triangulation._extract_triangulation_params(args, {}) |
49 | 50 | assertmask_isNone
|
50 | 51 | assertargs_== [mask]
|
51 |
| -# the positional maskhas tobecatched downstream because this must pass |
| 52 | +# the positional maskmustbecaught downstream because this must pass |
52 | 53 | # unknown args through
|
53 | 54 |
|
54 | 55 |
|
55 |
| -delx |
56 |
| -dely |
57 |
| -deltriangles |
58 |
| -delmask |
| 56 | +deftest_triangulation_init(): |
| 57 | +x= [-1,0,1,0] |
| 58 | +y= [0,-1,0,1] |
| 59 | +withpytest.raises(ValueError,match="x and y must be equal-length"): |
| 60 | +mtri.Triangulation(x, [1,2]) |
| 61 | +withpytest.raises( |
| 62 | +ValueError, |
| 63 | +match=r"triangles must be a \(N, 3\) int array, but found shape " |
| 64 | +r"\(3,\)"): |
| 65 | +mtri.Triangulation(x,y, [0,1,2]) |
| 66 | +withpytest.raises( |
| 67 | +ValueError, |
| 68 | +match=r"triangles must be a \(N, 3\) int array, not 'other'"): |
| 69 | +mtri.Triangulation(x,y,'other') |
| 70 | +withpytest.raises(ValueError,match="found value 99"): |
| 71 | +mtri.Triangulation(x,y, [[0,1,99]]) |
| 72 | +withpytest.raises(ValueError,match="found value -1"): |
| 73 | +mtri.Triangulation(x,y, [[0,1,-1]]) |
59 | 74 |
|
60 | 75 |
|
61 | 76 | deftest_delaunay():
|
@@ -223,6 +238,49 @@ def test_tripcolor():
|
223 | 238 | plt.title('facecolors')
|
224 | 239 |
|
225 | 240 |
|
| 241 | +deftest_tripcolor_color(): |
| 242 | +x= [-1,0,1,0] |
| 243 | +y= [0,-1,0,1] |
| 244 | +fig,ax=plt.subplots() |
| 245 | +withpytest.raises(ValueError,match="Missing color parameter"): |
| 246 | +ax.tripcolor(x,y) |
| 247 | +withpytest.raises(ValueError,match="The length of C must match either"): |
| 248 | +ax.tripcolor(x,y, [1,2,3]) |
| 249 | +withpytest.raises(ValueError, |
| 250 | +match="length of facecolors must match .* triangles"): |
| 251 | +ax.tripcolor(x,y,facecolors=[1,2,3,4]) |
| 252 | +withpytest.raises(ValueError, |
| 253 | +match="'gouraud' .* at the points.* not at the faces"): |
| 254 | +ax.tripcolor(x,y,facecolors=[1,2],shading='gouraud') |
| 255 | +withpytest.raises(ValueError, |
| 256 | +match="'gouraud' .* at the points.* not at the faces"): |
| 257 | +ax.tripcolor(x,y, [1,2],shading='gouraud')# faces |
| 258 | +withpytest.raises(ValueError, |
| 259 | +match=r"pass C positionally or facecolors via keyword"): |
| 260 | +ax.tripcolor(x,y,C=[1,2,3,4]) |
| 261 | + |
| 262 | +# smoke test for valid color specifications (via C or facecolors) |
| 263 | +ax.tripcolor(x,y, [1,2,3,4])# edges |
| 264 | +ax.tripcolor(x,y, [1,2,3,4],shading='gouraud')# edges |
| 265 | +ax.tripcolor(x,y, [1,2])# faces |
| 266 | +ax.tripcolor(x,y,facecolors=[1,2])# faces |
| 267 | + |
| 268 | + |
| 269 | +deftest_tripcolor_warnings(): |
| 270 | +x= [-1,0,1,0] |
| 271 | +y= [0,-1,0,1] |
| 272 | +C= [0.4,0.5] |
| 273 | +fig,ax=plt.subplots() |
| 274 | +# additional parameters |
| 275 | +withpytest.warns(UserWarning,match="Additional positional parameters"): |
| 276 | +ax.tripcolor(x,y,C,'unused_positional') |
| 277 | +# facecolors takes precednced over C |
| 278 | +withpytest.warns(UserWarning,match="Positional parameter C .*no effect"): |
| 279 | +ax.tripcolor(x,y,C,facecolors=C) |
| 280 | +withpytest.warns(UserWarning,match="Positional parameter C .*no effect"): |
| 281 | +ax.tripcolor(x,y,'interpreted as C',facecolors=C) |
| 282 | + |
| 283 | + |
226 | 284 | deftest_no_modify():
|
227 | 285 | # Test that Triangulation does not modify triangles array passed to it.
|
228 | 286 | triangles=np.array([[3,2,0], [3,1,0]],dtype=np.int32)
|
|