From 1589995775400c9e498391eebe45ad0c490d78f9 Mon Sep 17 00:00:00 2001 From: q-posev Date: Mon, 13 Sep 2021 11:46:31 +0200 Subject: [PATCH] do not use warnings for an attempt to overwrite in the Python API --- python/test/test_api.py | 8 ++------ src/templates_front/templator_front.org | 24 ++++-------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/python/test/test_api.py b/python/test/test_api.py index 756277d..ae1a1ab 100644 --- a/python/test/test_api.py +++ b/python/test/test_api.py @@ -38,8 +38,6 @@ except: #============ WRITE THE DATA IN THE TEST FILE ============# #=========================================================# - - # create TREXIO file and open it for writing test_file = trexio.File(output_filename, mode='w', back_end=TEST_TREXIO_BACKEND) @@ -59,11 +57,9 @@ try: except: raise -import warnings -warnings.filterwarnings("error") try: trexio.write_nucleus_num(test_file, nucleus_num*2) -except UserWarning: +except trexio.Error: print("Attempt to overwrite nucleus_num: checked.") # initialize charge arrays as a list and convert it to numpy array @@ -160,7 +156,7 @@ np.testing.assert_array_almost_equal(rcharges_np, charges_np, decimal=8) # unsafe call to read_safe should fail with error message corresponding to TREXIO_UNSAFE_ARRAY_DIM try: rcharges_fail = trexio.read_nucleus_charge(test_file2, dim=nucleus_num*5) -except Exception: +except trexio.Error: print("Unsafe call to safe API: checked") # safe call to read array of int values (nuclear indices) diff --git a/src/templates_front/templator_front.org b/src/templates_front/templator_front.org index 7deba75..37fefb2 100644 --- a/src/templates_front/templator_front.org +++ b/src/templates_front/templator_front.org @@ -1410,11 +1410,7 @@ def write_$group_num$(trexio_file, num_w: int) -> None: try: rc = pytr.trexio_write_$group_num$(trexio_file.pytrexio_s, num_w) if rc != TREXIO_SUCCESS: - if rc == TREXIO_ATTR_ALREADY_EXISTS: - import warnings - warnings.warn(string_of_error(rc)) - else: - raise Error(rc) + raise Error(rc) except: raise #+end_src @@ -2070,11 +2066,7 @@ def write_$group_dset$(trexio_file, dset_w) -> None: rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_w) if rc != TREXIO_SUCCESS: - if rc == TREXIO_DSET_ALREADY_EXISTS: - import warnings - warnings.warn(string_of_error(rc)) - else: - raise Error(rc) + raise Error(rc) #+end_src #+begin_src python :tangle read_dset_data_front.py @@ -2687,11 +2679,7 @@ def write_$group_dset$(trexio_file, dset_w: list) -> None: rc = pytr.trexio_write_$group_dset$(trexio_file.pytrexio_s, dset_w, max_str_length) if rc != TREXIO_SUCCESS: - if rc == TREXIO_DSET_ALREADY_EXISTS: - import warnings - warnings.warn(string_of_error(rc)) - else: - raise Error(rc) + raise Error(rc) except: raise @@ -2980,11 +2968,7 @@ def write_$group_str$(trexio_file, str_w: str) -> None: rc = pytr.trexio_write_$group_str$(trexio_file.pytrexio_s, str_w, max_str_length) if rc != TREXIO_SUCCESS: - if rc == TREXIO_ATTR_ALREADY_EXISTS: - import warnings - warnings.warn(string_of_error(rc)) - else: - raise Error(rc) + raise Error(rc) except: raise #+end_src