Commit a5dc2bc8 authored by payno's avatar payno

[h5py] add opening mode in h5py.File

parent 08f228cc
Pipeline #14865 failed with stage
in 6 minutes and 57 seconds
......@@ -84,7 +84,7 @@ class TestNxWriting(unittest.TestCase):
writer = XASWriter()
writer.output_file = self.h5_file
writer(self.xas_obj)
with h5py.File(self.h5_file) as hdf:
with h5py.File(self.h5_file, 'r') as hdf:
self.assertTrue('scan1' in hdf.keys())
self.assertTrue('data' in hdf['scan1'].keys())
self.assertTrue('absorbed_beam' in hdf['scan1'].keys())
......
......@@ -85,7 +85,7 @@ class TestNormalizationMultipleSpectrum(unittest.TestCase):
spectra_path = '/data/NXdata/data'
channel_path = '/data/NXdata/Channel'
filename = os.path.join(self.output_dir, 'myfile.h5')
with h5py.File(filename) as f:
with h5py.File(filename, 'w') as f:
f[spectra_path] = self.spectra
f[channel_path] = self.energy
......
......@@ -245,7 +245,7 @@ class TestSaveFlowAuto(unittest.TestCase):
writer.output_file = self.h5_file
writer(out)
with h5py.File(self.h5_file) as hdf:
with h5py.File(self.h5_file, 'r') as hdf:
self.assertTrue('scan1' in hdf.keys())
self.assertTrue('data' in hdf['scan1'].keys())
self.assertTrue('absorbed_beam' in hdf['scan1'].keys())
......
......@@ -49,7 +49,7 @@ class TestRoi(unittest.TestCase):
spectra_path = '/data/NXdata/data'
channel_path = '/data/NXdata/Channel'
filename = os.path.join(self.output_dir, 'myfile.h5')
with h5py.File(filename) as f:
with h5py.File(filename, 'w') as f:
f[spectra_path] = self.spectra
f[channel_path] = self.energy
......
......@@ -100,7 +100,7 @@ class TestXASObject(unittest.TestCase):
spectra_path = '/data/NXdata/data'
channel_path = '/data/NXdata/Channel'
filename = os.path.join(self.output_dir, 'myfile.h5')
with h5py.File(filename) as f:
with h5py.File(filename, 'w') as f:
f[spectra_path] = self.spectra
f[channel_path] = self.energy
......
......@@ -489,7 +489,7 @@ class XASObject(object):
'stored')
else:
process_flow = self.get_process_flow()
with h5py.File(self.linked_h5_file) as h5f:
with h5py.File(self.linked_h5_file, 'w') as h5f:
for index, process_ in process_flow.items():
del h5f[process_['_h5py_path']]
......@@ -505,8 +505,8 @@ class XASObject(object):
flow = self.get_process_flow()
entry = self.entry
with h5py.File(self.__h5_file) as source_hdf:
with h5py.File(h5_file_target) as target_hdf:
with h5py.File(self.__h5_file, 'w') as source_hdf:
with h5py.File(h5_file_target, 'w') as target_hdf:
target_entry = target_hdf.require_group(entry)
def remove_entry_prefix(name):
return name.replace('/'+entry+'/', '', 1)
......
......@@ -148,7 +148,7 @@ def write_xas_proc(h5_file, entry, process, data, processing_order,
"""
process_name = 'xas_process_' + str(processing_order)
# write the xasproc
with h5py.File(h5_file) as h5f:
with h5py.File(h5_file, 'w') as h5f:
nx_entry = h5f.require_group('/'.join((data_path, entry)))
nx_entry.attrs["NX_class"] = "NXentry"
......@@ -216,7 +216,7 @@ def write_xas(h5_file, entry, energy, mu, sample=None, start_time=None,
:param str title: experiment title
:param str definition: experiment definition
"""
with h5py.File(h5_file) as h5f:
with h5py.File(h5_file, 'w') as h5f:
nx_entry = h5f.require_group('/'.join((data_path, entry)))
nx_entry.attrs["NX_class"] = "NXentry"
......@@ -297,7 +297,7 @@ def get_xasproc(h5_file, entry):
return res
res = []
with h5py.File(h5_file) as h5f:
with h5py.File(h5_file, 'w') as h5f:
try:
root_group = h5f[entry]
except KeyError:
......
......@@ -132,7 +132,7 @@ class TestSimpleLarchWorkflow(OrangeWorflowTest):
self.assertTrue(os.path.exists(self.output_file))
# test outputfile
with h5py.File(self.output_file) as hdf5:
with h5py.File(self.output_file, 'r') as hdf5:
self.assertTrue('scan1' in hdf5)
scan_grp = hdf5['scan1']
self.assertTrue('absorbed_beam' in scan_grp)
......
Markdown is supported
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