Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing image scalebar export test #359

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions rsciio/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def test_save_load_cycle_kwds(dtype, ext, tmp_path):
def test_export_scalebar(ext, tmp_path):
hs = pytest.importorskip("hyperspy.api", reason="hyperspy not installed")
pytest.importorskip("matplotlib_scalebar")
import matplotlib.pyplot as plt

# Use np.uint8 to be able to save as BMP
pixels = 64
data = np.arange(pixels**2).reshape((pixels, pixels)).astype(np.uint8)
Expand All @@ -114,14 +116,16 @@ def test_export_scalebar(ext, tmp_path):
s.axes_manager[1].units = "nm"

filename = tmp_path / f"test_scalebar_export.{ext}"
if ext in ["bmp", "gif"]:
if ext in plt.figure().canvas.get_supported_filetypes():
s.save(filename, scalebar=True)
else:
# file format not supported by matplotlib backend
with pytest.raises(ValueError):
s.save(filename, scalebar=True)
with pytest.raises(ValueError):
s.save(filename, output_size=512)
s.save(filename)
else:
s.save(filename, scalebar=True)

s_reload = hs.load(filename)
assert s.data.shape == s_reload.data.shape

Expand Down
Loading