From ba46aec2dcd37db5f90d6c4b4a576c863633dca5 Mon Sep 17 00:00:00 2001 From: Henri Payno Date: Mon, 30 Aug 2021 09:32:18 +0200 Subject: [PATCH 1/2] [app] add test on the application --- nxtomomill/app/test/test_dxfile2nx_app.py | 63 ++++++++++++++++++++ nxtomomill/app/test/test_edf2nx_app.py | 58 ++++++++++++++++++ nxtomomill/app/test/test_h52nx_app.py | 65 ++++++++++++++++++++ nxtomomill/app/test/test_patch_nx_app.py | 72 +++++++++++++++++++++++ 4 files changed, 258 insertions(+) create mode 100644 nxtomomill/app/test/test_dxfile2nx_app.py create mode 100644 nxtomomill/app/test/test_edf2nx_app.py create mode 100644 nxtomomill/app/test/test_h52nx_app.py create mode 100644 nxtomomill/app/test/test_patch_nx_app.py diff --git a/nxtomomill/app/test/test_dxfile2nx_app.py b/nxtomomill/app/test/test_dxfile2nx_app.py new file mode 100644 index 0000000..258b5f6 --- /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 0000000..bdc2b33 --- /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 0000000..13a9bd4 --- /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 0000000..b88981f --- /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" -- GitLab From 7e111199603c3a954e2865ccfc4e616820593c52 Mon Sep 17 00:00:00 2001 From: Henri Payno Date: Mon, 30 Aug 2021 10:01:53 +0200 Subject: [PATCH 2/2] [gitlabci] install inplace for code coverage --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e826c8a..85bc2cf 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/ -- GitLab