|
12 | 12 | from matplotlib.testing.decorators import image_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 | +def test_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 | + assert x_ is x |
| 37 | + assert y_ is y |
| 38 | + assert_array_equal(triangles_, triangles) |
| 39 | + assert mask_ is mask |
| 40 | + assert args_ == other_args |
| 41 | + assert kwargs_ == other_kwargs |
| 42 | + |
| 43 | + |
| 44 | +def test_extract_triangulation_positional_mask(): |
| 45 | + global x, y, triangles, mask |
| 46 | + # mask cannot be passed positionally |
| 47 | + x_, y_, triangles_, mask_, args_, kwargs_ = \ |
| 48 | + mtri.Triangulation._extract_triangulation_params(x, y, triangles, mask) |
| 49 | + assert mask_ is None |
| 50 | + assert args_ == [mask] |
| 51 | + # the positional mask has to be catched downstream because this must pass |
| 52 | + # unknown args through |
| 53 | + |
| 54 | + |
| 55 | +del x |
| 56 | +del y |
| 57 | +del triangles |
| 58 | +del mask |
| 59 | + |
| 60 | + |
15 | 61 | def test_delaunay(): |
16 | 62 | # No duplicate points, regular grid. |
17 | 63 | nx = 5 |
|
0 commit comments