diff options
| author | Melissa Weber Mendonça <melissawm.github@gmail.com> | 2022-06-06 12:46:27 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-06-06 12:46:27 -0300 |
| commit | aeb2b21670e6071467db1aa237fb2772616787e0 (patch) | |
| tree | 290d864bdfca6d0eef257c6894117d677036c573 /numpy/f2py/tests/test_docs.py | |
| parent | c3e5246df67e231d4549952fc8b5c1333a5e7ff7 (diff) | |
| parent | 5c0ecb52890f92d43cf70519cd5491b8415b3710 (diff) | |
| download | numpy-aeb2b21670e6071467db1aa237fb2772616787e0.tar.gz | |
Merge pull request #19388 from pearu/enh-f2py-character-support
Co-authored-by: Rohit Goswami <rog32@hi.is>
Diffstat (limited to 'numpy/f2py/tests/test_docs.py')
| -rw-r--r-- | numpy/f2py/tests/test_docs.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/numpy/f2py/tests/test_docs.py b/numpy/f2py/tests/test_docs.py new file mode 100644 index 000000000..6631dd82c --- /dev/null +++ b/numpy/f2py/tests/test_docs.py @@ -0,0 +1,55 @@ +import os +import pytest +import numpy as np +from numpy.testing import assert_array_equal, assert_equal +from . import util + + +def get_docdir(): + # assuming that documentation tests are run from a source + # directory + return os.path.abspath(os.path.join( + os.path.dirname(__file__), + '..', '..', '..', + 'doc', 'source', 'f2py', 'code')) + + +pytestmark = pytest.mark.skipif( + not os.path.isdir(get_docdir()), + reason=('Could not find f2py documentation sources' + f' ({get_docdir()} does not exists)')) + + +def _path(*a): + return os.path.join(*((get_docdir(),) + a)) + + +class TestDocAdvanced(util.F2PyTest): + # options = ['--debug-capi', '--build-dir', '/tmp/build-f2py'] + sources = [_path('asterisk1.f90'), _path('asterisk2.f90'), + _path('ftype.f')] + + def test_asterisk1(self): + foo = getattr(self.module, 'foo1') + assert_equal(foo(), b'123456789A12') + + def test_asterisk2(self): + foo = getattr(self.module, 'foo2') + assert_equal(foo(2), b'12') + assert_equal(foo(12), b'123456789A12') + assert_equal(foo(24), b'123456789A123456789B') + + def test_ftype(self): + ftype = self.module + ftype.foo() + assert_equal(ftype.data.a, 0) + ftype.data.a = 3 + ftype.data.x = [1, 2, 3] + assert_equal(ftype.data.a, 3) + assert_array_equal(ftype.data.x, + np.array([1, 2, 3], dtype=np.float32)) + ftype.data.x[1] = 45 + assert_array_equal(ftype.data.x, + np.array([1, 45, 3], dtype=np.float32)) + + # TODO: implement test methods for other example Fortran codes |
