From 75a230bf6d3c777fb241631729a5bb0f304fbd80 Mon Sep 17 00:00:00 2001 From: dmitry-ganyushin Date: Mon, 19 Oct 2020 14:30:29 -0400 Subject: [PATCH] Added a test to write/read a python string for low-level API --- testing/adios2/bindings/python/CMakeLists.txt | 1 + .../bindings/python/TestBPWriteReadString.py | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 testing/adios2/bindings/python/TestBPWriteReadString.py diff --git a/testing/adios2/bindings/python/CMakeLists.txt b/testing/adios2/bindings/python/CMakeLists.txt index 8f3bf44888..d35fd4f8ad 100644 --- a/testing/adios2/bindings/python/CMakeLists.txt +++ b/testing/adios2/bindings/python/CMakeLists.txt @@ -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) diff --git a/testing/adios2/bindings/python/TestBPWriteReadString.py b/testing/adios2/bindings/python/TestBPWriteReadString.py new file mode 100644 index 0000000000..3b684c2a92 --- /dev/null +++ b/testing/adios2/bindings/python/TestBPWriteReadString.py @@ -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 ganyushindi@ornl.gov +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()