-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2489 from dmitry-ganyushin/f2338-python-str-fullAPI
Added a test to write/read a python string for low-level python API
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |