Commit ed02965
committed
Fix running contour's test_internal_cpp_api directly.
The `matplotlib._contour` module is lazily loaded, so using it directly
(as done in this test) may fail if something else doesn't load it. This
test would fail if it was the first contour-related test run in a
process (if testing in parallel), or if just called as the only test,
i.e., this commit fixes:
```
$ pytest -k test_internal_cpp_api lib/matplotlib/tests/test_contour.py
__________ test_internal_cpp_api[args0-TypeError-function takes exactly 6 arguments (0 given)] __________
args = (), cls = <class 'TypeError'>, message = 'function takes exactly 6 arguments (0 given)'
@pytest.mark.parametrize("args, cls, message", [
((), TypeError,
'function takes exactly 6 arguments (0 given)'),
((1, 2, 3, 4, 5, 6), ValueError,
'Expected 2-dimensional array, got 0'),
(([[0]], [[0]], [[]], None, True, 0), ValueError,
'x, y and z must all be 2D arrays with the same dimensions'),
(([[0]], [[0]], [[0]], None, True, 0), ValueError,
'x, y and z must all be at least 2x2 arrays'),
((*[np.arange(4).reshape((2, 2))] * 3, [[0]], True, 0), ValueError,
'If mask is set it must be a 2D array with the same dimensions as x.'),
])
def test_internal_cpp_api(args, cls, message): # Github issue 8197.
with pytest.raises(cls, match=re.escape(message)):
> mpl._contour.QuadContourGenerator(*args)
E AttributeError: module 'matplotlib' has no attribute '_contour'
lib/matplotlib/tests/test_contour.py:269: AttributeError
This is a corollary to b672f68 for tri.1 parent d2f25c9 commit ed02965
1 file changed
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
| 268 | + | |
268 | 269 | | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
272 | 273 | | |
| 274 | + | |
273 | 275 | | |
274 | 276 | | |
275 | 277 | | |
| |||
0 commit comments