diff --git a/nose_unit.cfg b/nose_unit.cfg index a34b709f157..67d7aba7110 100644 --- a/nose_unit.cfg +++ b/nose_unit.cfg @@ -6,5 +6,5 @@ nologcapture=1 verbosity=2 where=yt with-timer=1 -ignore-files=(test_load_errors.py|test_load_sample.py|test_commons.py|test_ambiguous_fields.py|test_field_access_pytest.py|test_save.py|test_line_annotation_unit.py) +ignore-files=(test_load_errors.py|test_load_sample.py|test_commons.py|test_ambiguous_fields.py|test_field_access_pytest.py|test_save.py|test_line_annotation_unit.py|test_eps_writer.py) exclude-test=yt.frontends.gdf.tests.test_outputs.TestGDF diff --git a/tests/tests.yaml b/tests/tests.yaml index 621bad06615..61be5178d54 100644 --- a/tests/tests.yaml +++ b/tests/tests.yaml @@ -186,6 +186,7 @@ other_tests: - '--ignore-files=test_load_sample.py' - '--ignore-files=test_field_access_pytest.py' - '--ignore-files=test_ambiguous_fields.py' + - '--ignore-files=test_eps_writer.py' - "--ignore-files=test_save.py" - '--exclude-test=yt.frontends.gdf.tests.test_outputs.TestGDF' cookbook: diff --git a/yt/testing.py b/yt/testing.py index 09832f9eca0..c021e8f047a 100644 --- a/yt/testing.py +++ b/yt/testing.py @@ -7,6 +7,7 @@ import shutil import tempfile import unittest +from shutil import which import matplotlib import numpy as np @@ -1364,6 +1365,29 @@ def ftrue(func): return ffalse +def requires_external_executable(*names): + import pytest + + def deco(func): + missing = [] + for name in names: + if which(name) is None: + missing.append(name) + + # note that order between these two decorators matters + @pytest.mark.skipif( + missing, + reason=f"missing external executable(s): {', '.join(missing)}", + ) + @functools.wraps(func) + def inner_func(*args, **kwargs): + return func(*args, **kwargs) + + return inner_func + + return deco + + class TempDirTest(unittest.TestCase): """ A test class that runs in a temporary directory and diff --git a/yt/visualization/eps_writer.py b/yt/visualization/eps_writer.py index f489f969a5f..bcb9a1ad661 100644 --- a/yt/visualization/eps_writer.py +++ b/yt/visualization/eps_writer.py @@ -1,3 +1,5 @@ +import os + import numpy as np import pyx from matplotlib import cm, pyplot as plt @@ -743,7 +745,7 @@ def colorbar( # Convert the colormap into a string x = np.linspace(1, 0, 256) - cm_string = cm.get_cmap[name](x, bytes=True)[:, 0:3].tobytes() + cm_string = cm.get_cmap(name)(x, bytes=True)[:, 0:3].tobytes() cmap_im = pyx.bitmap.image(imsize[0], imsize[1], "RGB", cm_string) if orientation == "top" or orientation == "bottom": @@ -1143,6 +1145,7 @@ def save_fig(self, filename="test", format="eps", resolution=250): >>> d = DualEPS() >>> d.axis_box(xrange=(0, 100), yrange=(1e-3, 1), ylog=True) """ + filename = os.path.expanduser(filename) if format == "eps": self.canvas.writeEPSfile(filename) elif format == "pdf": diff --git a/yt/visualization/tests/test_eps_writer.py b/yt/visualization/tests/test_eps_writer.py new file mode 100644 index 00000000000..5e8c6c1fe84 --- /dev/null +++ b/yt/visualization/tests/test_eps_writer.py @@ -0,0 +1,28 @@ +import yt +from yt.testing import fake_amr_ds, requires_external_executable, requires_module + + +@requires_external_executable("tex") +@requires_module("pyx") +def test_eps_writer(tmp_path): + import yt.visualization.eps_writer as eps + + fields = [ + ("gas", "density"), + ("gas", "temperature"), + ] + units = [ + "g/cm**3", + "K", + ] + ds = fake_amr_ds(fields=fields, units=units) + slc = yt.SlicePlot( + ds, + "z", + fields=fields, + ) + eps_fig = eps.multiplot_yt(2, 1, slc, bare_axes=True) + eps_fig.scale_line(0.2, "5 cm") + savefile = tmp_path / "multi" + eps_fig.save_fig(savefile, format="eps") + assert savefile.with_suffix(".eps").exists()