Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
test_docs.py67 linesDownload Raw Back to tests
1from pathlib import Path
2
3import pytest
4
5import numpy as np
6from numpy.testing import assert_array_equal, assert_equal
7
8from . import util
9
10
11def get_docdir():
12    parents = Path(__file__).resolve().parents
13    try:
14        # Assumes that spin is used to run tests
15        nproot = parents[8]
16    except IndexError:
17        docdir = None
18    else:
19        docdir = nproot / "doc" / "source" / "f2py" / "code"
20    if docdir and docdir.is_dir():
21        return docdir
22    # Assumes that an editable install is used to run tests
23    return parents[3] / "doc" / "source" / "f2py" / "code"
24
25
26pytestmark = pytest.mark.skipif(
27    not get_docdir().is_dir(),
28    reason=f"Could not find f2py documentation sources"
29    f"({get_docdir()} does not exist)",
30)
31
32def _path(*args):
33    return get_docdir().joinpath(*args)
34
35@pytest.mark.slow
36class TestDocAdvanced(util.F2PyTest):
37    # options = ['--debug-capi', '--build-dir', '/tmp/build-f2py']
38    sources = [_path('asterisk1.f90'), _path('asterisk2.f90'),
39               _path('ftype.f')]
40
41    def test_asterisk1(self):
42        foo = self.module.foo1
43        assert_equal(foo(), b'123456789A12')
44
45    def test_asterisk2(self):
46        foo = self.module.foo2
47        assert_equal(foo(2), b'12')
48        assert_equal(foo(12), b'123456789A12')
49        assert_equal(foo(20), b'123456789A123456789B')
50
51    def test_ftype(self):
52        ftype = self.module
53        ftype.foo()
54        assert_equal(ftype.data.a, 0)
55        ftype.data.a = 3
56        ftype.data.x = [1, 2, 3]
57        assert_equal(ftype.data.a, 3)
58        assert_array_equal(ftype.data.x,
59                           np.array([1, 2, 3], dtype=np.float32))
60        ftype.data.x[1] = 45
61        assert_array_equal(ftype.data.x,
62                           np.array([1, 45, 3], dtype=np.float32))
63        # gh-26718 Cleanup for repeated test runs
64        ftype.data.a = 0
65
66    # TODO: implement test methods for other example Fortran codes
67 
codekingpro/portable-devtools · Team Ai