Skip to content

Commit

Permalink
Merge pull request #3496 from neutrinoceros/hotfix_eps_writer
Browse files Browse the repository at this point in the history
BUG: fix two bugs in yt.visualization.eps_writer
  • Loading branch information
jzuhone authored Sep 3, 2021
2 parents befb8c6 + 6c889fa commit b1e3e28
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nose_unit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 24 additions & 0 deletions yt/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import tempfile
import unittest
from shutil import which

import matplotlib
import numpy as np
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion yt/visualization/eps_writer.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import numpy as np
import pyx
from matplotlib import cm, pyplot as plt
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down
28 changes: 28 additions & 0 deletions yt/visualization/tests/test_eps_writer.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit b1e3e28

Please sign in to comment.