From a5dc2bc87a7fc83b3ca8e3bda4a96bf3256191e6 Mon Sep 17 00:00:00 2001
From: payno <payno@linazimov.esrf.fr>
Date: Mon, 30 Sep 2019 08:49:05 +0200
Subject: [PATCH] [h5py] add opening mode in h5py.File

---
 est/core/process/pymca/test/test_io.py            | 2 +-
 est/core/process/pymca/test/test_normalization.py | 2 +-
 est/core/process/pymca/test/test_workflow.py      | 2 +-
 est/core/process/test/test_roi.py                 | 2 +-
 est/core/test/test_types.py                       | 2 +-
 est/core/types.py                                 | 6 +++---
 est/io/io.py                                      | 6 +++---
 orangecontrib/est/test/test_larch_workflow.py     | 2 +-
 8 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/est/core/process/pymca/test/test_io.py b/est/core/process/pymca/test/test_io.py
index 7e20beb3..da3cf2bc 100644
--- a/est/core/process/pymca/test/test_io.py
+++ b/est/core/process/pymca/test/test_io.py
@@ -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())
diff --git a/est/core/process/pymca/test/test_normalization.py b/est/core/process/pymca/test/test_normalization.py
index 7f7aca36..df883b08 100644
--- a/est/core/process/pymca/test/test_normalization.py
+++ b/est/core/process/pymca/test/test_normalization.py
@@ -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
 
diff --git a/est/core/process/pymca/test/test_workflow.py b/est/core/process/pymca/test/test_workflow.py
index 54beb64e..5ede0493 100644
--- a/est/core/process/pymca/test/test_workflow.py
+++ b/est/core/process/pymca/test/test_workflow.py
@@ -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())
diff --git a/est/core/process/test/test_roi.py b/est/core/process/test/test_roi.py
index d7e64071..8c320278 100644
--- a/est/core/process/test/test_roi.py
+++ b/est/core/process/test/test_roi.py
@@ -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
 
diff --git a/est/core/test/test_types.py b/est/core/test/test_types.py
index 3495d185..2d3892cb 100644
--- a/est/core/test/test_types.py
+++ b/est/core/test/test_types.py
@@ -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
 
diff --git a/est/core/types.py b/est/core/types.py
index dc677dac..9cf27427 100644
--- a/est/core/types.py
+++ b/est/core/types.py
@@ -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)
diff --git a/est/io/io.py b/est/io/io.py
index be6ec249..e7300c6a 100644
--- a/est/io/io.py
+++ b/est/io/io.py
@@ -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:
diff --git a/orangecontrib/est/test/test_larch_workflow.py b/orangecontrib/est/test/test_larch_workflow.py
index cbe5119d..779dbc38 100644
--- a/orangecontrib/est/test/test_larch_workflow.py
+++ b/orangecontrib/est/test/test_larch_workflow.py
@@ -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)
-- 
GitLab