Skip to content

Commit

Permalink
Increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpre committed Jul 8, 2023
1 parent 1494c20 commit acf1943
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
3 changes: 0 additions & 3 deletions rsciio/bruker/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# SFS (Single File System) (used in bcf technology) is present in
# the same library.


# Plugin characteristics
# ----------------------
from os.path import splitext, basename
from math import ceil
import logging
Expand Down
12 changes: 4 additions & 8 deletions rsciio/edax/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@
_logger = logging.getLogger(__name__)


spd_extensions = ("spd", "SPD", "Spd")
spc_extensions = ("spc", "SPC", "Spc")


def get_spd_dtype_list(endianess="<"):
"""
Get the data type list for an SPD map.
Expand Down Expand Up @@ -1002,8 +998,8 @@ def file_reader(
The file specification is available at :ref:`edax-file_specification`.
"""

ext = os.path.splitext(filename)[1][1:]
if ext in spd_extensions:
ext = os.path.splitext(filename)[1][1:].lower()
if ext == "spd":
return spd_reader(
filename,
lazy,
Expand All @@ -1013,10 +1009,10 @@ def file_reader(
load_all_spc=load_all_spc,
**kwds,
)
elif ext in spc_extensions:
elif ext == "spc":
return spc_reader(filename, lazy, endianess, load_all_spc=load_all_spc, **kwds)
else:
raise IOError("Did not understand input file format.")
raise ValueError(f"'{ext}' is not a supported extension for the edax reader.")


file_reader.__doc__ %= (FILENAME_DOC, LAZY_DOC, ENDIANESS_DOC, RETURNS_DOC)
8 changes: 8 additions & 0 deletions rsciio/tests/test_bruker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from hyperspy.misc.test_utils import assert_deep_almost_equal

from rsciio.bruker import file_reader


test_files = [
"30x30_instructively_packed_16bit_compressed.bcf",
"16x16_12bit_packed_8bit.bcf",
Expand Down Expand Up @@ -316,3 +319,8 @@ def test_bruker_XRF():
assert s.metadata.Acquisition_instrument.TEM.beam_energy == 50
assert s.axes_manager.signal_shape == (4096,)
assert s.axes_manager.navigation_shape == ()


def test_unsupported_extension():
with pytest.raises(ValueError):
file_reader("fname.unsupported_extension")
8 changes: 8 additions & 0 deletions rsciio/tests/test_edax.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
import numpy as np
import pytest

from rsciio.edax import file_reader


hs = pytest.importorskip("hyperspy.api", reason="hyperspy not installed")
requests = pytest.importorskip("requests", reason="requests not installed")

Expand Down Expand Up @@ -596,3 +599,8 @@ def test_spc_reading(self):
)
np.testing.assert_allclose(spc_header.kV, sem_dict["beam_energy"])
np.testing.assert_allclose(spc_header.numElem, len(elements))


def test_unsupported_extension():
with pytest.raises(ValueError):
file_reader("fname.unsupported_extension")
6 changes: 6 additions & 0 deletions rsciio/tests/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ def test_rsciio_dir():
assert dir(rsciio) == ["IO_PLUGINS", "__version__"]


def test_rsciio_utils():
from rsciio.utils import hdf5 as utils_hdf5

assert dir(utils_hdf5) == ["list_datasets_in_file", "read_metadata_from_file"]


def test_import_all():
from rsciio import IO_PLUGINS

Expand Down
7 changes: 6 additions & 1 deletion rsciio/tests/test_tia.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import traits.api as t

from rsciio.tia._api import load_ser_file
from rsciio.tia._api import load_ser_file, file_reader


TEST_DATA_PATH = Path(__file__).parent / "data" / "tia"
Expand Down Expand Up @@ -526,3 +526,8 @@ def test_metadata_diffraction():
s.metadata.Acquisition_instrument.TEM.microscope
== "Tecnai 200 kV D2267 SuperTwin"
)


def test_unsupported_extension():
with pytest.raises(ValueError):
file_reader("fname.unsupported_extension")

0 comments on commit acf1943

Please sign in to comment.