Skip to content

Commit

Permalink
Merge pull request #2489 from dmitry-ganyushin/f2338-python-str-fullAPI
Browse files Browse the repository at this point in the history
Added a test to write/read a python string for low-level python API
  • Loading branch information
dmitry-ganyushin authored Oct 19, 2020
2 parents 7263faa + 75a230b commit ea89b91
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions testing/adios2/bindings/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(ADIOS2_HAVE_MPI)
add_python_mpi_test(BPWriteReadTypes)
add_python_mpi_test(BPWriteTypesHighLevelAPI)
add_python_mpi_test(BPWriteTypesHighLevelAPILocal)
add_python_mpi_test(BPWriteReadString)
add_python_mpi_test(BPReadMultisteps)
add_python_mpi_test(BPWriteRead2D)
add_python_mpi_test(BPBlocksInfo)
Expand Down
46 changes: 46 additions & 0 deletions testing/adios2/bindings/python/TestBPWriteReadString.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

#
# Distributed under the OSI-approved Apache License, Version 2.0. See
# accompanying file Copyright.txt for details.
#
# TestBPWriteReadString.py: test writing/reading Python string type
# in ADIOS2 File Write
# Created on: Oct 19, 2020
# Author: Dmitry Ganyushin [email protected]
import unittest
from mpi4py import MPI
import adios2

class TestAdiosWriteReadString(unittest.TestCase):

def test_adios_read_string(self):
# MPI
comm = MPI.COMM_WORLD
the_string = 'hello adios'
bpfilename = 'string_test.bp'
varname = 'mystringvar'
N_steps = 10
adios = adios2.ADIOS(comm)
ioWrite = adios.DeclareIO('ioWriter')
ad_engine = ioWrite.Open(bpfilename, adios2.Mode.Write)
var_mystringvar = ioWrite.DefineVariable(varname)
for step in range(N_steps):
ad_engine.BeginStep()
ad_engine.Put(var_mystringvar, the_string + str(step))
ad_engine.EndStep()
ad_engine.Close()

ioRead = adios.DeclareIO('ioReader')
ad_engine = ioRead.Open(bpfilename, adios2.Mode.Read)
var_read_mystringvar = ioRead.InquireVariable(varname)
for step in range(N_steps):
ad_engine.BeginStep()
result = ad_engine.Get(var_read_mystringvar)
ad_engine.EndStep()
self.assertEqual(result, the_string + str(step))
ad_engine.Close()


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

0 comments on commit ea89b91

Please sign in to comment.