Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a test to read strings for all steps at once in python #2544

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions testing/adios2/bindings/python/TestBPWriteReadString.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,21 @@
from mpi4py import MPI
import adios2

N_STEPS = 3


class TestAdiosWriteReadStringfullAPI(unittest.TestCase):

def test_write_read_string_fullAPI(self):
comm = MPI.COMM_WORLD
theString = 'hello adios'
bpFilename = 'string_test_fullAPI.bp'
varname = 'mystringvar'
NSteps = 3
adios = adios2.ADIOS(comm)
ioWrite = adios.DeclareIO('ioWriter')
adEngine = ioWrite.Open(bpFilename, adios2.Mode.Write)
varMyString = ioWrite.DefineVariable(varname)
for step in range(NSteps):
for step in range(N_STEPS):
adEngine.BeginStep()
adEngine.Put(varMyString, theString + str(step))
adEngine.EndStep()
Expand All @@ -32,7 +34,7 @@ def test_write_read_string_fullAPI(self):
ioRead = adios.DeclareIO('ioReader')
adEngine = ioRead.Open(bpFilename, adios2.Mode.Read)
varReadMyString = ioRead.InquireVariable(varname)
for step in range(NSteps):
for step in range(N_STEPS):
adEngine.BeginStep()
result = adEngine.Get(varReadMyString)
adEngine.EndStep()
Expand All @@ -44,11 +46,10 @@ def test_write_read_string_highAPI(self):
theString = 'hello adios'
bpFilename = 'string_test_highAPI.bp'
varname = 'mystringvar'
NSteps = 3

with adios2.open(bpFilename, "w", comm) as fh:

for step in range(NSteps):
for step in range(N_STEPS):
fh.write(varname, theString + str(step), end_step=True)

with adios2.open(bpFilename, "r", comm) as fh:
Expand All @@ -58,6 +59,20 @@ def test_write_read_string_highAPI(self):
self.assertEqual("".join([chr(s) for s in result]),
theString + str(step))

def test_read_strings_all_steps(self):
fileName = 'string_test_all.bp'
with adios2.open(fileName, "w") as fh:
for i in range(N_STEPS):
fh.write("string_variable", "written {}".format(i))
fh.end_step()

with adios2.open(fileName, "r") as fh:
n = fh.steps()
name = "string_variable"
result = fh.read_string(name, 0, n)
expected_str = ["written {}".format(i) for i in range(n)]
self.assertEqual(result, expected_str)


if __name__ == '__main__':
unittest.main()