1111import gpgi
1212from gpgi ._lib import _deposit_ngp_2D
1313
14+ from importlib .util import find_spec
15+ HAVE_PYTEST_MPL = find_spec ("pytest-mpl" ) is not None
1416
1517@pytest .fixture ()
1618def sample_2D_dataset ():
@@ -120,11 +122,12 @@ def fake_dep(*args, metadata=None, **kwargs):
120122@pytest .mark .parametrize ("method" , ["ngp" , "cic" , "tsc" ])
121123@pytest .mark .mpl_image_compare
122124def test_2D_deposit (sample_2D_dataset , method ):
123- from matplotlib .figure import Figure
124125
125126 ds = sample_2D_dataset
126127 particle_density = ds .deposit ("mass" , method = method )
127128
129+ if not HAVE_PYTEST_MPL : return
130+ from matplotlib .figure import Figure
128131 fig = Figure ()
129132 ax = fig .add_subplot ()
130133
@@ -178,6 +181,7 @@ def test_1D_deposit(method, grid_type):
178181 if method == "ngp" :
179182 assert mass .sum () == ds .particles .count
180183
184+ if not HAVE_PYTEST_MPL : return
181185 fig = Figure ()
182186 ax = fig .add_subplot ()
183187 ax .set (xlabel = "x" , ylabel = "particle mass" , title = f"Deposition method '{ method } '" )
@@ -241,10 +245,9 @@ def test_3D_deposit(method, dtype):
241245 assert deposit_3D .shape == tuple (a - 2 for a in full_deposit_3D .shape )
242246
243247
248+
244249@pytest .mark .mpl_image_compare
245250def test_readme_example ():
246- from matplotlib .figure import Figure
247-
248251 nx = ny = 64
249252 nparticles = 600_000
250253
@@ -271,6 +274,10 @@ def test_readme_example():
271274
272275 particle_mass = ds .deposit ("mass" , method = "nearest_grid_point" )
273276
277+ if not HAVE_PYTEST_MPL : return
278+ from matplotlib .figure import Figure
279+
280+
274281 fig = Figure ()
275282 ax = fig .add_subplot ()
276283 ax .set (aspect = 1 , xlabel = "x" , ylabel = "y" )
0 commit comments