Coverage for nilearn/plotting/surface/tests/conftest.py: 0%
38 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 12:32 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-16 12:32 +0200
1"""Test fixtures used by nilearn.plotting.surface tests."""
3import numpy as np
4import pytest
6from nilearn._utils.helpers import is_matplotlib_installed, is_plotly_installed
7from nilearn.surface import SurfaceImage
10def pytest_generate_tests(metafunc):
11 """Check installed packages and set engines to be used for the tests.
13 https://docs.pytest.org/en/stable/example/parametrize.html#deferring-the-setup-of-parametrized-resources
14 """
15 if "engine" in metafunc.fixturenames:
16 installed_engines = []
17 if is_matplotlib_installed():
18 installed_engines.append("matplotlib")
19 if is_plotly_installed():
20 installed_engines.append("plotly")
21 metafunc.parametrize("engine", installed_engines, indirect=True)
24@pytest.fixture
25def engine(request):
26 """Return each of the engines detected by pytest_generate_tests."""
27 return request.param
30@pytest.fixture
31def plt(request, engine):
32 """Return the fixture for setup and teardown of test depending on the
33 engine.
34 """
35 if engine == "matplotlib":
36 return request.getfixturevalue("matplotlib_pyplot")
37 elif engine == "plotly":
38 return request.getfixturevalue("plotly")
41@pytest.fixture
42def bg_map(rng, in_memory_mesh):
43 """Return a background map with positive value."""
44 return np.abs(rng.standard_normal(size=in_memory_mesh.n_vertices))
47@pytest.fixture
48def surface_image_roi(surf_mask_1d):
49 """SurfaceImage for plotting."""
50 return surf_mask_1d
53@pytest.fixture
54def parcellation(in_memory_mesh):
55 parcellation = np.zeros((in_memory_mesh.n_vertices,))
56 parcellation[in_memory_mesh.faces[3]] = 1
57 parcellation[in_memory_mesh.faces[5]] = 2
58 return parcellation
61@pytest.fixture
62def surface_image_parcellation(rng, in_memory_mesh):
63 data = rng.integers(100, size=(in_memory_mesh.n_vertices, 1)).astype(float)
64 parcellation = SurfaceImage(
65 mesh={"left": in_memory_mesh, "right": in_memory_mesh},
66 data={"left": data, "right": data},
67 )
68 return parcellation