diff options
author | Pearu Peterson <pearu.peterson@gmail.com> | 2021-07-01 17:54:45 +0300 |
---|---|---|
committer | Rohit Goswami <rog32@hi.is> | 2022-06-05 15:19:12 +0000 |
commit | d4e11c7a2eb64861275facb076d47ccd135fa28c (patch) | |
tree | 307e937f15807094ae81b8a78d791bab4526c851 /numpy/f2py/tests/test_crackfortran.py | |
parent | e5fcb9d52c1b9d3c9caf067849ad1bba128c7e17 (diff) | |
download | numpy-d4e11c7a2eb64861275facb076d47ccd135fa28c.tar.gz |
ENH: Support character string arrays
TST: added test for issue #18684
ENH: f2py opens files with correct encoding, fixes #635
TST: added test for issue #6308
TST: added test for issue #4519
TST: added test for issue #3425
ENH: Implement user-defined hooks support for post-processing f2py data structure. Implement character BC hook.
ENH: Add support for detecting utf-16 and utf-32 encodings.
Diffstat (limited to 'numpy/f2py/tests/test_crackfortran.py')
-rw-r--r-- | numpy/f2py/tests/test_crackfortran.py | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/numpy/f2py/tests/test_crackfortran.py b/numpy/f2py/tests/test_crackfortran.py index ea618bf33..53edfc091 100644 --- a/numpy/f2py/tests/test_crackfortran.py +++ b/numpy/f2py/tests/test_crackfortran.py @@ -1,3 +1,4 @@ +import codecs import pytest import numpy as np from numpy.f2py.crackfortran import markinnerspaces @@ -18,7 +19,7 @@ class TestNoSpace(util.F2PyTest): assert np.allclose(k, w + 1) self.module.subc([w, k]) assert np.allclose(k, w + 1) - assert self.module.t0(23) == b"2" + assert self.module.t0("23") == b"2" class TestPublicPrivate: @@ -122,7 +123,6 @@ class TestMarkinnerspaces: assert markinnerspaces("a 'b c' 'd e'") == "a 'b@_@c' 'd@_@e'" assert markinnerspaces(r'a "b c" "d e"') == r'a "b@_@c" "d@_@e"' - class TestDimSpec(util.F2PyTest): """This test suite tests various expressions that are used as dimension specifications. @@ -231,3 +231,30 @@ class TestModuleDeclaration: mod = crackfortran.crackfortran([str(fpath)]) assert len(mod) == 1 assert mod[0]["vars"]["abar"]["="] == "bar('abar')" + +class TestEval(util.F2PyTest): + def test_eval_scalar(self): + eval_scalar = crackfortran._eval_scalar + + assert eval_scalar('123', {}) == '123' + assert eval_scalar('12 + 3', {}) == '15' + assert eval_scalar('a + b', dict(a=1, b=2)) == '3' + assert eval_scalar('"123"', {}) == "'123'" + + +class TestFortranReader(util.F2PyTest): + @pytest.mark.parametrize("encoding", + ['ascii', 'utf-8', 'utf-16', 'utf-32']) + def test_input_encoding(self, tmp_path, encoding): + # gh-635 + f_path = tmp_path / f"input_with_{encoding}_encoding.f90" + # explicit BOM is required for UTF8 + bom = {'utf-8': codecs.BOM_UTF8}.get(encoding, b'') + with f_path.open('w', encoding=encoding) as ff: + ff.write(bom.decode(encoding) + + """ + subroutine foo() + end subroutine foo + """) + mod = crackfortran.crackfortran([str(f_path)]) + assert mod[0]['name'] == 'foo' |