Skip to content
Snippets Groups Projects
Commit e912e008 authored by Joao P C Bertoldo's avatar Joao P C Bertoldo
Browse files

correct test

parent d2a0866e
No related branches found
No related tags found
1 merge request!6Draft: Resolve "py-bkg-rm"
......@@ -135,6 +135,9 @@ def catch_silx_io_exceptions(get_data_func, logger_=None):
if "File" in msg and "not found" in msg:
raise FileNotFoundError(f"{data_url.file_path()=}", ex) from ex
if "File" in msg and "must be a file path" in msg:
raise FileNotFoundError(f"{data_url.file_path()=}", ex) from ex
if "File" in msg and "can't be read as HDF5" in msg:
raise BadDataUrlFileNotHDF5Error("Not an HDF file.") from ex
......@@ -150,6 +153,9 @@ def catch_silx_io_exceptions(get_data_func, logger_=None):
# todo go back to f"{var=}"
raise ValueError(f"{data_url.path()=} missing data path (h5 internal link after '::')") from ex
if msg == "expected bytes, NoneType found":
raise ValueError(f"{data_url.path()=} missing data path (h5 internal link after '::')") from ex
raise
except ValueError as ex:
......@@ -161,8 +167,6 @@ def catch_silx_io_exceptions(get_data_func, logger_=None):
if "Data path from URL" in msg and "not found" in msg:
raise BadDataUrlError(f"{data_url.data_path()=} not in {data_url.file_path()=}") from ex
raise
logger_.debug(f"data successfully loaded with `{get_data_func.__name__}`")
return data
......
......@@ -38,7 +38,7 @@ def output_h5(tmp_path):
path = tmp_path / "output.h5"
grouplink = "/computed_suff"
urlstr = f"silx:{str(path.absolute())}::{grouplink}"
return path, grouplink, urlstr, None # the none is not necessary, but the code elsewhere is expecting 4 values...
return path, grouplink, urlstr, f"{urlstr}/data"
@pytest.fixture
......
......@@ -146,6 +146,7 @@ def main(
# i.e.: they are supposed to be in the right type (argparse's job)
# but the values could be anything, so we ensure that the assumpions
# are actually respected
# todo encapsulate validations to share them with widgets?
logger.debug("validating arguments")
......@@ -176,6 +177,12 @@ def main(
darknz, darkny, darknx = dark_shape
nz, nx, ny = data_shape
if not (0 < median_validity <= nz):
raise ValueError(f"{median_validity=} must be positive and at most {nz=}")
if not (0 < median_window <= nz):
raise ValueError(f"{median_window=} must be positive and at most {nz=}")
if (darknx, darkny) != (nx, ny):
raise ValueError(f"incompatible dark/data shapes on XY {dark_shape=} {data_shape=}")
......@@ -279,7 +286,7 @@ def main(
data=data,
backgrounds=background_medians if save_backgrounds else None,
parameters=dict(
normalization=normalization,
normalization=normalization.value,
normalization_numerator=normalization_numerator,
margin_bounding_box=margin_bounding_box,
median_validity=median_validity,
......@@ -459,8 +466,8 @@ class DocstringsAction(DocstringsActionAbstract):
return [
main,
# preprocess,
moving_median_removal.remove_moving_medians,
xyfilter_median.xyfilter_median,
remove_moving_medians,
xyfilter_median,
parse.verbosity_args2level,
]
......
......@@ -119,7 +119,7 @@ def test_parser_bad_args(parser_bad_option_args):
@pytest.fixture
def main_kwargs_real00(realdata00_url, darkend00_url, output_url):
def main_kwargs(realdata00_url, darkend00_url, output_url):
"""a possible set of parameters"""
return dict(
input_url=realdata00_url,
......@@ -140,7 +140,7 @@ def main_kwargs_real00(realdata00_url, darkend00_url, output_url):
# ====================================== normal calls
def test_main_dryrun(main_kwargs_with_bkgs, monkeypatch):
def test_main_dryrun(main_kwargs, monkeypatch):
def mock_get_data(*_, **__):
return np.ones((200, 500, 500))
......@@ -158,13 +158,13 @@ def test_main_dryrun(main_kwargs_with_bkgs, monkeypatch):
monkeypatch.setattr(main, "xyfilter_median", mock_xyfilter_median)
monkeypatch.setattr(main, "dicttoh5", mock_dicttoh5)
main.main(**main_kwargs_with_bkgs)
main.main(**main_kwargs)
@pytest.mark.slow
def test_main(main_kwargs_with_bkgs, output_h5):
def test_main(main_kwargs, output_h5):
main.main(**main_kwargs_with_bkgs)
main.main(**main_kwargs)
path, _, urlstr, __ = output_h5
......@@ -190,7 +190,7 @@ def test_main(main_kwargs_with_bkgs, output_h5):
lambda s: s.split("::", 1)[0], # missing data link
]
)
def main_kwargs_invalid_input_url(request, main_kwargs):
def main_kwargs_invalid_input_url(request, main_kwargs, realdata00_h5):
"""modify the input url to force a break"""
_, __, urlstr = realdata00_h5
url = DataUrl(request.param(urlstr))
......@@ -218,10 +218,10 @@ def main_kwargs_bad_moving_window_params(request, main_kwargs):
return {**main_kwargs, **dict(median_validity=request.param[0], median_window=request.param[1])}
def test_main_kwargs_invalid_moving_window_params(main_kwargs_bad_window_sizes):
def test_main_kwargs_invalid_moving_window_params(main_kwargs_bad_moving_window_params):
with pytest.raises(ValueError):
main.main(**main_kwargs_bad_window_sizes)
main.main(**main_kwargs_bad_moving_window_params)
@pytest.fixture
......@@ -231,10 +231,10 @@ def main_kwargs_input_doesnt_exist(main_kwargs):
return {**main_kwargs, **dict(input_url=input_url)}
def test_main_kwargs_file_not_found(main_kwargs_not_found_input):
def test_main_kwargs_file_not_found(main_kwargs_input_doesnt_exist):
with pytest.raises(FileNotFoundError):
main.main(**main_kwargs_not_found_input)
main.main(**main_kwargs_input_doesnt_exist)
@pytest.fixture
......
......@@ -2,8 +2,9 @@ import logging
import pytest
from pydct.preprocess import zwise_median
from silx.io import get_data
from ._fixtures import darkend00_h5, output_h5
from ._fixtures import darkend00_h5, darkend00_url, output_h5, output_url
zwise_median.logger.setLevel(logging.DEBUG)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment