|
2 | 2 | from contextlib import nullcontext |
3 | 3 | from copy import deepcopy |
4 | 4 | from functools import partial |
| 5 | +from importlib.util import find_spec |
5 | 6 | from threading import Lock |
6 | 7 |
|
7 | 8 | import numpy as np |
|
11 | 12 | import gpgi |
12 | 13 | from gpgi._lib import _deposit_ngp_2D |
13 | 14 |
|
14 | | -from importlib.util import find_spec |
15 | 15 | HAVE_PYTEST_MPL = find_spec("pytest-mpl") is not None |
16 | 16 |
|
| 17 | + |
17 | 18 | @pytest.fixture() |
18 | 19 | def sample_2D_dataset(): |
19 | 20 | nparticles = 100 |
@@ -122,12 +123,13 @@ def fake_dep(*args, metadata=None, **kwargs): |
122 | 123 | @pytest.mark.parametrize("method", ["ngp", "cic", "tsc"]) |
123 | 124 | @pytest.mark.mpl_image_compare |
124 | 125 | def test_2D_deposit(sample_2D_dataset, method): |
125 | | - |
126 | 126 | ds = sample_2D_dataset |
127 | 127 | particle_density = ds.deposit("mass", method=method) |
128 | 128 |
|
129 | | - if not HAVE_PYTEST_MPL: return |
| 129 | + if not HAVE_PYTEST_MPL: |
| 130 | + return |
130 | 131 | from matplotlib.figure import Figure |
| 132 | + |
131 | 133 | fig = Figure() |
132 | 134 | ax = fig.add_subplot() |
133 | 135 |
|
@@ -181,7 +183,8 @@ def test_1D_deposit(method, grid_type): |
181 | 183 | if method == "ngp": |
182 | 184 | assert mass.sum() == ds.particles.count |
183 | 185 |
|
184 | | - if not HAVE_PYTEST_MPL: return |
| 186 | + if not HAVE_PYTEST_MPL: |
| 187 | + return |
185 | 188 | fig = Figure() |
186 | 189 | ax = fig.add_subplot() |
187 | 190 | ax.set(xlabel="x", ylabel="particle mass", title=f"Deposition method '{method}'") |
@@ -245,7 +248,6 @@ def test_3D_deposit(method, dtype): |
245 | 248 | assert deposit_3D.shape == tuple(a - 2 for a in full_deposit_3D.shape) |
246 | 249 |
|
247 | 250 |
|
248 | | - |
249 | 251 | @pytest.mark.mpl_image_compare |
250 | 252 | def test_readme_example(): |
251 | 253 | nx = ny = 64 |
@@ -274,10 +276,10 @@ def test_readme_example(): |
274 | 276 |
|
275 | 277 | particle_mass = ds.deposit("mass", method="nearest_grid_point") |
276 | 278 |
|
277 | | - if not HAVE_PYTEST_MPL: return |
| 279 | + if not HAVE_PYTEST_MPL: |
| 280 | + return |
278 | 281 | from matplotlib.figure import Figure |
279 | 282 |
|
280 | | - |
281 | 283 | fig = Figure() |
282 | 284 | ax = fig.add_subplot() |
283 | 285 | ax.set(aspect=1, xlabel="x", ylabel="y") |
|
0 commit comments