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 test suite #186

Merged
merged 4 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
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
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
Fixed Show fixed Hide fixed
Dismissed Show dismissed Hide dismissed


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_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 @@
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 @@
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
Loading