Commit aecb0dbf authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Add test with nonexisting target dir

parent d58b994f
Pipeline #32897 passed with stages
in 4 minutes and 54 seconds
...@@ -191,7 +191,6 @@ class HDF5DatasetAnalyzer(DatasetAnalyzer): ...@@ -191,7 +191,6 @@ class HDF5DatasetAnalyzer(DatasetAnalyzer):
self._compute_or_load_flats() self._compute_or_load_flats()
def _get_rotation_angles(self): def _get_rotation_angles(self):
if self._rot_angles is None: if self._rot_angles is None:
angles = np.array(self.dataset_scanner.rotation_angle) angles = np.array(self.dataset_scanner.rotation_angle)
......
...@@ -208,9 +208,10 @@ class NXFlatField: ...@@ -208,9 +208,10 @@ class NXFlatField:
tmp_fallback: bool, optional tmp_fallback: bool, optional
Whether to write to /tmp if writing fails. Default is True. Whether to write to /tmp if writing fails. Default is True.
""" """
if self.results_file is None: results_file = self.results_file
if results_file is None:
raise ValueError("Please provide results_file parameter when instantiating the class") raise ValueError("Please provide results_file parameter when instantiating the class")
target_dir = os.path.dirname(self.results_file) target_dir = os.path.dirname(results_file)
if not(os.access(target_dir, os.W_OK)): if not(os.access(target_dir, os.W_OK)):
if not(tmp_fallback): if not(tmp_fallback):
raise ValueError("Cannot write to %s" % target_dir) raise ValueError("Cannot write to %s" % target_dir)
...@@ -220,7 +221,8 @@ class NXFlatField: ...@@ -220,7 +221,8 @@ class NXFlatField:
% (target_dir, tempdir) % (target_dir, tempdir)
) )
target_dir = tempdir target_dir = tempdir
writer = NXProcessWriter(self.results_file, entry=entry, overwrite=True) results_file = os.path.join(target_dir, os.path.basename(results_file))
writer = NXProcessWriter(results_file, entry=entry, overwrite=True)
h5_results_path = writer.write( h5_results_path = writer.write(
flats_and_darks, process_name, config=self.get_config() flats_and_darks, process_name, config=self.get_config()
) )
...@@ -229,7 +231,7 @@ class NXFlatField: ...@@ -229,7 +231,7 @@ class NXFlatField:
links[img_type] = {} links[img_type] = {}
for img_idx in imgs.keys(): for img_idx in imgs.keys():
links[img_type][img_idx] = DataUrl( links[img_type][img_idx] = DataUrl(
file_path=self.results_file, file_path=results_file,
data_path=os.path.join(h5_results_path, img_type, str(img_idx)) data_path=os.path.join(h5_results_path, img_type, str(img_idx))
) )
return links return links
......
...@@ -37,7 +37,14 @@ test_nxflatfield_scenarios = [ ...@@ -37,7 +37,14 @@ test_nxflatfield_scenarios = [
"darks_reduction": "mean", "darks_reduction": "mean",
"results_file": path.join(tempdir, "ff_multiple_with_save.h5"), "results_file": path.join(tempdir, "ff_multiple_with_save.h5"),
}, },
{
"name": "multiple_with_save_tmp_fallback",
"flats_pos": [slice(0, 10), slice(30, 40)],
"darks_pos": [slice(95, 100)],
"flats_reduction": "median",
"darks_reduction": "mean",
"results_file": path.join("/tmp/nonexisting_dir", "ff_multiple_with_save.h5"),
},
] ]
def generate_nx_dataset(fname, n_projs, flats_pos, darks_pos, h5path=None): def generate_nx_dataset(fname, n_projs, flats_pos, darks_pos, h5path=None):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment