1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 20:35:44 +01:00

do not use warnings for an attempt to overwrite in the Python API

This commit is contained in:
q-posev 2021-09-13 11:46:31 +02:00
parent 2bd4ef9bfd
commit 1589995775
2 changed files with 6 additions and 26 deletions

View File

@ -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)

View File

@ -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