mirror of
https://github.com/TREX-CoE/trexio.git
synced 2024-11-03 20:54:07 +01:00
replace some integers with TREXIO-native constants
This commit is contained in:
parent
1f98604d58
commit
9bbae8fd7c
30
src/test.py
30
src/test.py
@ -8,23 +8,23 @@ from pytrexio import *
|
|||||||
#=========================================================#
|
#=========================================================#
|
||||||
|
|
||||||
# 0: TREXIO_HDF5 ; 1: TREXIO_TEXT
|
# 0: TREXIO_HDF5 ; 1: TREXIO_TEXT
|
||||||
TEST_TREXIO_BACKEND = 1
|
TEST_TREXIO_BACKEND = TREXIO_TEXT
|
||||||
OUTPUT_FILENAME_TEXT = 'test_py_swig.dir'
|
OUTPUT_FILENAME_TEXT = 'test_py_swig.dir'
|
||||||
OUTPUT_FILENAME_HDF5 = 'test_py_swig.h5'
|
OUTPUT_FILENAME_HDF5 = 'test_py_swig.h5'
|
||||||
|
|
||||||
|
|
||||||
if TEST_TREXIO_BACKEND == 0:
|
if TEST_TREXIO_BACKEND == TREXIO_HDF5:
|
||||||
output_filename = OUTPUT_FILENAME_HDF5
|
output_filename = OUTPUT_FILENAME_HDF5
|
||||||
elif TEST_TREXIO_BACKEND == 1:
|
elif TEST_TREXIO_BACKEND == TREXIO_TEXT:
|
||||||
output_filename = OUTPUT_FILENAME_TEXT
|
output_filename = OUTPUT_FILENAME_TEXT
|
||||||
else:
|
else:
|
||||||
raise ValueError ('Specify one of the supported back end as TEST_TREXIO_BACKEND')
|
raise ValueError ('Specify one of the supported back ends as TEST_TREXIO_BACKEND')
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if TEST_TREXIO_BACKEND == 0:
|
if TEST_TREXIO_BACKEND == TREXIO_HDF5:
|
||||||
os.remove(output_filename)
|
os.remove(output_filename)
|
||||||
if TEST_TREXIO_BACKEND == 1:
|
elif TEST_TREXIO_BACKEND == TREXIO_TEXT:
|
||||||
shutil.rmtree(output_filename)
|
shutil.rmtree(output_filename)
|
||||||
except:
|
except:
|
||||||
print (f'Test file {output_filename} does not exist')
|
print (f'Test file {output_filename} does not exist')
|
||||||
@ -38,7 +38,7 @@ test_file = trexio_open(output_filename, 'w', TEST_TREXIO_BACKEND)
|
|||||||
nucleus_num = 12
|
nucleus_num = 12
|
||||||
|
|
||||||
rc = trexio_write_nucleus_num(test_file, nucleus_num)
|
rc = trexio_write_nucleus_num(test_file, nucleus_num)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
charges = doubleArray(nucleus_num)
|
charges = doubleArray(nucleus_num)
|
||||||
for i in range(nucleus_num):
|
for i in range(nucleus_num):
|
||||||
@ -48,12 +48,12 @@ for i in range(nucleus_num):
|
|||||||
charges[i] = 1.
|
charges[i] = 1.
|
||||||
|
|
||||||
rc = trexio_write_nucleus_charge(test_file, charges)
|
rc = trexio_write_nucleus_charge(test_file, charges)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
point_group = 'B3U'
|
point_group = 'B3U'
|
||||||
|
|
||||||
rc = trexio_write_nucleus_point_group(test_file, point_group, 10)
|
rc = trexio_write_nucleus_point_group(test_file, point_group, 10)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
labels = [
|
labels = [
|
||||||
'C',
|
'C',
|
||||||
@ -70,10 +70,10 @@ labels = [
|
|||||||
'H']
|
'H']
|
||||||
|
|
||||||
rc = trexio_write_nucleus_label(test_file, labels, 10)
|
rc = trexio_write_nucleus_label(test_file, labels, 10)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
rc = trexio_close(test_file)
|
rc = trexio_close(test_file)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
#==========================================================#
|
#==========================================================#
|
||||||
#============ READ THE DATA FROM THE TEST FILE ============#
|
#============ READ THE DATA FROM THE TEST FILE ============#
|
||||||
@ -91,7 +91,7 @@ for i in range(nucleus_num):
|
|||||||
charges2[i] = -1.
|
charges2[i] = -1.
|
||||||
|
|
||||||
rc = trexio_read_nucleus_charge(test_file2, charges2)
|
rc = trexio_read_nucleus_charge(test_file2, charges2)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
for i in range(nucleus_num):
|
for i in range(nucleus_num):
|
||||||
assert charges2[i]==charges[i]
|
assert charges2[i]==charges[i]
|
||||||
|
|
||||||
@ -99,15 +99,15 @@ for i in range(nucleus_num):
|
|||||||
#rc, label_2d = trexio_read_nucleus_label(test_file2, 10)
|
#rc, label_2d = trexio_read_nucleus_label(test_file2, 10)
|
||||||
# [WIP]: currently only low-level routines (return one long string instead of an array of strings) work
|
# [WIP]: currently only low-level routines (return one long string instead of an array of strings) work
|
||||||
rc, labels_1d = trexio_read_nucleus_label_low(test_file2, 10)
|
rc, labels_1d = trexio_read_nucleus_label_low(test_file2, 10)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
labels_2d = [label for label in labels_1d.split('\n') if label]
|
labels_2d = [label for label in labels_1d.split(TREXIO_DELIM) if label]
|
||||||
print(labels_2d)
|
print(labels_2d)
|
||||||
for i in range(nucleus_num):
|
for i in range(nucleus_num):
|
||||||
assert labels_2d[i]==labels[i]
|
assert labels_2d[i]==labels[i]
|
||||||
|
|
||||||
rc = trexio_close(test_file2)
|
rc = trexio_close(test_file2)
|
||||||
assert rc==0
|
assert rc==TREXIO_SUCCESS
|
||||||
|
|
||||||
#==========================================================#
|
#==========================================================#
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user