diff options
author | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-04-15 12:28:41 +0200 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2017-05-02 21:30:36 +0200 |
commit | b8d0498eb1463e900a6c07311c0c1f80f5611bad (patch) | |
tree | 5dddea4b52578f8fdec6d73d12d63c2bbfba9d08 | |
parent | 43914a4421fbabdd63a1cb73ef4c48d626498aaa (diff) | |
download | numpy-b8d0498eb1463e900a6c07311c0c1f80f5611bad.tar.gz |
TST: add a char array input test
-rw-r--r-- | numpy/f2py/tests/src/string/char.f90 | 29 | ||||
-rw-r--r-- | numpy/f2py/tests/test_string.py | 26 |
2 files changed, 55 insertions, 0 deletions
diff --git a/numpy/f2py/tests/src/string/char.f90 b/numpy/f2py/tests/src/string/char.f90 new file mode 100644 index 000000000..bb7985ce5 --- /dev/null +++ b/numpy/f2py/tests/src/string/char.f90 @@ -0,0 +1,29 @@ +MODULE char_test + +CONTAINS + +SUBROUTINE change_strings(strings, n_strs, out_strings) + IMPLICIT NONE + + ! Inputs + INTEGER, INTENT(IN) :: n_strs + CHARACTER, INTENT(IN), DIMENSION(2,n_strs) :: strings + CHARACTER, INTENT(OUT), DIMENSION(2,n_strs) :: out_strings + +!f2py INTEGER, INTENT(IN) :: n_strs +!f2py CHARACTER, INTENT(IN), DIMENSION(2,n_strs) :: strings +!f2py CHARACTER, INTENT(OUT), DIMENSION(2,n_strs) :: strings + + ! Misc. + INTEGER*4 :: j + + + DO j=1, n_strs + out_strings(1,j) = strings(1,j) + out_strings(2,j) = 'A' + END DO + +END SUBROUTINE change_strings + +END MODULE char_test + diff --git a/numpy/f2py/tests/test_string.py b/numpy/f2py/tests/test_string.py new file mode 100644 index 000000000..10022ebb1 --- /dev/null +++ b/numpy/f2py/tests/test_string.py @@ -0,0 +1,26 @@ +from __future__ import division, absolute_import, print_function + +import os + +from numpy.testing import run_module_suite, assert_array_equal, dec +import numpy as np +import util + + +def _path(*a): + return os.path.join(*((os.path.dirname(__file__),) + a)) + +class TestString(util.F2PyTest): + sources = [_path('src', 'string', 'char.f90')] + + @dec.slow + def test_char(self): + strings = np.array(['ab', 'cd', 'ef'], dtype='c').T + inp, out = self.module.char_test.change_strings(strings, strings.shape[1]) + assert_array_equal(inp, strings) + expected = strings.copy() + expected[1, :] = 'AAA' + assert_array_equal(out, expected) + +if __name__ == "__main__": + run_module_suite() |