8000 Fix running contour's test_internal_cpp_api directly. · matplotlib/matplotlib@ed02965 · GitHub
[go: up one dir, main page]

Skip to content

Commit ed02965

Browse files
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

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

lib/matplotlib/tests/test_contour.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,13 @@ def test_contourf_symmetric_locator():
265265
'If mask is set it must be a 2D array with the same dimensions as x.'),
266266
])
267267
def test_internal_cpp_api(args, cls, message): # Github issue 8197.
268+
from matplotlib import _contour # noqa: ensure lazy-loaded module *is* loaded.
268269
with pytest.raises(cls, match=re.escape(message)):
269270
mpl._contour.QuadContourGenerator(*args)
270271

271272

272273
def test_internal_cpp_api_2():
274+
from matplotlib import _contour # noqa: ensure lazy-loaded module *is* loaded.
273275
arr = [[0, 1], [2, 3]]
274276
qcg = mpl._contour.QuadContourGenerator(arr, arr, arr, None, True, 0)
275277
with pytest.raises(

0 commit comments

Comments
 (0)
0