Skip to content

Commit

Permalink
Merge pull request #186 from ericpre/fix_test_suite
Browse files Browse the repository at this point in the history
Fix test suite
  • Loading branch information
ericpre authored Nov 26, 2023
2 parents a8a6eaa + 3ff5c38 commit 13507d4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ jobs:
- name: Install HyperSpy (dev)
run: |
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_major.zip
pip install https://github.com/hyperspy/exspy/archive/main.zip
pip install git+https://github.com/hyperspy/hyperspy.git@RELEASE_next_major
pip install git+https://github.com/hyperspy/exspy.git
- name: Install distribution
run: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Tests

on: [push, pull_request]
on: [push, pull_request, workflow_dispatch]

jobs:
run_test_site:
Expand Down Expand Up @@ -79,12 +79,12 @@ jobs:
if: ${{ ! contains(matrix.LABEL, 'without-hyperspy') }}
# Need to install hyperspy dev until hyperspy 2.0 is released
run: |
pip install https://github.com/hyperspy/hyperspy/archive/RELEASE_next_major.zip
pip install git+https://github.com/hyperspy/hyperspy.git@RELEASE_next_major
- name: Install (exspy)
if: ${{ ! contains(matrix.LABEL, '-minimum') && ! contains(matrix.LABEL, 'without-hyperspy') }}
run: |
pip install https://github.com/hyperspy/exspy/archive/main.zip
pip install git+https://github.com/hyperspy/exspy.git
- name: Install
shell: bash
Expand Down
90 changes: 43 additions & 47 deletions rsciio/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@

import pytest

import rsciio


def test_import_version():
from rsciio import __version__


def test_rsciio_dir():
import rsciio

assert dir(rsciio) == ["IO_PLUGINS", "__version__"]


Expand All @@ -39,8 +39,6 @@ def test_rsciio_utils():


def test_import_all():
from rsciio import IO_PLUGINS

plugin_name_to_remove = []

# Remove plugins which require not installed optional dependencies
Expand Down Expand Up @@ -85,21 +83,19 @@ def test_import_all():
except Exception:
plugin_name_to_remove.append("ZSPY")

IO_PLUGINS = list(
IO_PLUGINS_ = list(
filter(
lambda plugin: plugin["name"] not in set(plugin_name_to_remove),
IO_PLUGINS,
rsciio.IO_PLUGINS,
)
)

for plugin in IO_PLUGINS:
for plugin in IO_PLUGINS_:
importlib.import_module(plugin["api"])


def test_format_name_aliases():
from rsciio import IO_PLUGINS

for reader in IO_PLUGINS:
for reader in rsciio.IO_PLUGINS:
assert isinstance(reader["name"], str)
assert isinstance(reader["name_aliases"], list)
if reader["name_aliases"]:
Expand All @@ -119,40 +115,40 @@ def test_format_name_aliases():
assert isinstance(reader["non_uniform_axis"], bool)


def test_dir_plugins():
from rsciio import IO_PLUGINS

for plugin in IO_PLUGINS:
plugin_string = "rsciio.%s" % plugin["name"].lower()
# skip for missing optional dependencies
if plugin["name"] == "Blockfile":
pytest.importorskip("skimage")
elif plugin["name"] == "MRCZ":
pytest.importorskip("mrcz")
elif plugin["name"] in ["TIFF", "Phenom"]:
pytest.importorskip("tifffile")
elif plugin["name"] == "USID":
pytest.importorskip("pyUSID")
elif plugin["name"] == "ZSPY":
pytest.importorskip("zarr")
elif plugin["name"] in ["EMD", "JEOL"]:
pytest.importorskip("sparse")
plugin_module = importlib.import_module(plugin_string)

if plugin["name"] == "MSA":
assert dir(plugin_module) == [
"file_reader",
"file_writer",
"parse_msa_string",
]
elif plugin["name"] == "QuantumDetector":
assert dir(plugin_module) == [
"file_reader",
"load_mib_data",
"parse_exposures",
"parse_timestamps",
]
elif plugin["writes"] is False:
assert dir(plugin_module) == ["file_reader"]
else:
assert dir(plugin_module) == ["file_reader", "file_writer"]
@pytest.mark.parametrize("plugin", rsciio.IO_PLUGINS)
def test_dir_plugins(plugin):
plugin_string = "rsciio.%s" % plugin["name"].lower()
# skip for missing optional dependencies
if plugin["name"] == "Blockfile":
pytest.importorskip("skimage")
elif plugin["name"] == "Image":
pytest.importorskip("imageio")
elif plugin["name"] == "MRCZ":
pytest.importorskip("mrcz")
elif plugin["name"] in ["TIFF", "Phenom"]:
pytest.importorskip("tifffile")
elif plugin["name"] == "USID":
pytest.importorskip("pyUSID")
elif plugin["name"] == "ZSPY":
pytest.importorskip("zarr")
elif plugin["name"] in ["EMD", "HSPY", "NeXus"]:
pytest.importorskip("h5py")
plugin_module = importlib.import_module(plugin_string)

if plugin["name"] == "MSA":
assert dir(plugin_module) == [
"file_reader",
"file_writer",
"parse_msa_string",
]
elif plugin["name"] == "QuantumDetector":
assert dir(plugin_module) == [
"file_reader",
"load_mib_data",
"parse_exposures",
"parse_timestamps",
]
elif plugin["writes"] is False:
assert dir(plugin_module) == ["file_reader"]
else:
assert dir(plugin_module) == ["file_reader", "file_writer"]
1 change: 1 addition & 0 deletions upcoming_changes/186.maintenance.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix installing exspy/hyperspy on GitHub CI and test failing without optional dependencies

0 comments on commit 13507d4

Please sign in to comment.