diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e826c8acf5d2bc062bd56a08d32a083ea801ac93..85bc2cfe30d39fb31e4f9f3f1018b65356607321 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -64,7 +64,7 @@ doc: - install_silx - install_tomoscan - python -m pip install pytest-cov - - python -m pip install .[full] + - python -m pip install -e .[full] script: - python -m pytest --cov-config=.coveragerc --cov=nxtomomill nxtomomill/ diff --git a/nxtomomill/app/test/test_dxfile2nx_app.py b/nxtomomill/app/test/test_dxfile2nx_app.py new file mode 100644 index 0000000000000000000000000000000000000000..258b5f6a5b30790c2b999aad7e2b8dc6c912fb5f --- /dev/null +++ b/nxtomomill/app/test/test_dxfile2nx_app.py @@ -0,0 +1,63 @@ +# coding: utf-8 +# /*########################################################################## +# +# Copyright (c) 2015-2020 European Synchrotron Radiation Facility +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# ###########################################################################*/ + +""" +test the dxfile2nx application +""" + +__authors__ = [ + "H. Payno", +] +__license__ = "MIT" +__date__ = "30/08/2021" + + +import tempfile +from nxtomomill.test.utils.dxfile import MockDxFile +import os +import subprocess + + +def test_dxfile2nx_application(): + """test nxtomomill dxfile2nx input_file output_file""" + with tempfile.TemporaryDirectory() as folder: + dx_file_path = os.path.join(folder, "dxfile.dx") + nx_file_path = os.path.join(folder, "dxfile.nx") + n_projections = 50 + n_darks = 2 + n_flats = 4 + + mock = MockDxFile( + file_path=dx_file_path, + n_projection=n_projections, + n_darks=n_darks, + n_flats=n_flats, + ) + assert not os.path.exists(nx_file_path), "outputfile exists already" + process = subprocess.Popen( + ["nxtomomill", "dxfile2nx", dx_file_path, nx_file_path] + ) + stdout, stderr = process.communicate() + assert os.path.exists(nx_file_path), "outputfile doesn't exists" diff --git a/nxtomomill/app/test/test_edf2nx_app.py b/nxtomomill/app/test/test_edf2nx_app.py new file mode 100644 index 0000000000000000000000000000000000000000..bdc2b33860813a6a4eccf60916bece27fb600890 --- /dev/null +++ b/nxtomomill/app/test/test_edf2nx_app.py @@ -0,0 +1,58 @@ +# coding: utf-8 +# /*########################################################################## +# +# Copyright (c) 2015-2020 European Synchrotron Radiation Facility +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# ###########################################################################*/ + +""" +test the edf2nx application +""" + +__authors__ = [ + "H. Payno", +] +__license__ = "MIT" +__date__ = "30/08/2021" + + +import tempfile +from tomoscan.esrf.mock import MockEDF +import os +import subprocess + + +def test_edf2nx_application(): + """test nxtomomill edf2nx input_file output_file""" + with tempfile.TemporaryDirectory() as folder: + edf_acq_path = os.path.join(folder, "acquisition") + n_proj = 10 + MockEDF( + scan_path=edf_acq_path, + n_radio=n_proj, + n_ini_radio=n_proj, + ) + output_file = os.path.join(edf_acq_path, "nexus_file.nx") + + assert not os.path.exists(output_file), "output_file exists already" + process = subprocess.Popen(["nxtomomill", "edf2nx", edf_acq_path, output_file]) + stdout, stderr = process.communicate() + assert os.path.exists(output_file), "output_file doesn't exists" diff --git a/nxtomomill/app/test/test_h52nx_app.py b/nxtomomill/app/test/test_h52nx_app.py new file mode 100644 index 0000000000000000000000000000000000000000..13a9bd4faf2ee21179819b9d1d6f5c637067cf51 --- /dev/null +++ b/nxtomomill/app/test/test_h52nx_app.py @@ -0,0 +1,65 @@ +# coding: utf-8 +# /*########################################################################## +# +# Copyright (c) 2015-2020 European Synchrotron Radiation Facility +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# ###########################################################################*/ + +""" +test the h52nx application +""" + +__authors__ = [ + "H. Payno", +] +__license__ = "MIT" +__date__ = "30/08/2021" + + +import tempfile +from nxtomomill.test.utils.bliss import MockBlissAcquisition +import os +import subprocess + + +def test_h52nx_application(): + """test nxtomomill h52nx input_file output_file --single-file""" + with tempfile.TemporaryDirectory() as folder: + nx_file_path = os.path.join(folder, "acquisition.nx") + + bliss_mock = MockBlissAcquisition( + n_sample=2, + n_sequence=1, + n_scan_per_sequence=10, + n_darks=5, + n_flats=5, + with_nx_detector_attr=True, + output_dir=folder, + detector_name="pcolinux", + ) + + h5_file_path = bliss_mock.samples[0].sample_file + assert not os.path.exists(nx_file_path), "outputfile exists already" + process = subprocess.Popen( + ["nxtomomill", "h52nx", h5_file_path, nx_file_path, "--single-file"] + ) + stdout, stderr = process.communicate() + assert os.path.exists(nx_file_path), "outputfile doesn't exists" diff --git a/nxtomomill/app/test/test_patch_nx_app.py b/nxtomomill/app/test/test_patch_nx_app.py new file mode 100644 index 0000000000000000000000000000000000000000..b88981f1350f97646280f3d3ce425e4cb2b6390d --- /dev/null +++ b/nxtomomill/app/test/test_patch_nx_app.py @@ -0,0 +1,72 @@ +# coding: utf-8 +# /*########################################################################## +# +# Copyright (c) 2015-2020 European Synchrotron Radiation Facility +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +# +# ###########################################################################*/ + +""" +test the patch-nx application +""" + +__authors__ = [ + "H. Payno", +] +__license__ = "MIT" +__date__ = "30/08/2021" + + +import tempfile +from tomoscan.esrf.mock import MockHDF5 +import h5py +import os +import subprocess + + +def test_patch_nx_application(): + """test nxtomomill patch-nx input_file entry --invalid-frames XX:YY""" + + with tempfile.TemporaryDirectory() as folder: + nx_path = os.path.join(folder, "nexus_file.nx") + dim = 55 + nproj = 20 + scan = MockHDF5( + scan_path=nx_path, + n_proj=nproj, + n_ini_proj=nproj, + create_ini_dark=False, + create_ini_ref=False, + create_final_ref=False, + dim=dim, + ).scan + process = subprocess.Popen( + [ + "nxtomomill", + "patch-nx", + scan.master_file, + "entry", + "--invalid-frames", + "0:12", + ] + ) + stdout, stderr = process.communicate() + scan.clear_caches() + assert len(scan.projections) == 8, "Scan is expected to have 8 projections now"