File size: 2,532 Bytes
c6d3cdb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import os
import pytest
import numpy as np
from . import util
class TestIntentInOut(util.F2PyTest):
# Check that intent(in out) translates as intent(inout)
sources = [util.getpath("tests", "src", "regression", "inout.f90")]
@pytest.mark.slow
def test_inout(self):
# non-contiguous should raise error
x = np.arange(6, dtype=np.float32)[::2]
pytest.raises(ValueError, self.module.foo, x)
# check values with contiguous array
x = np.arange(3, dtype=np.float32)
self.module.foo(x)
assert np.allclose(x, [3, 1, 2])
class TestNegativeBounds(util.F2PyTest):
# Check that negative bounds work correctly
sources = [util.getpath("tests", "src", "negative_bounds", "issue_20853.f90")]
@pytest.mark.slow
def test_negbound(self):
xvec = np.arange(12)
xlow = -6
xhigh = 4
# Calculate the upper bound,
# Keeping the 1 index in mind
def ubound(xl, xh):
return xh - xl + 1
rval = self.module.foo(is_=xlow, ie_=xhigh,
arr=xvec[:ubound(xlow, xhigh)])
expval = np.arange(11, dtype = np.float32)
assert np.allclose(rval, expval)
class TestNumpyVersionAttribute(util.F2PyTest):
# Check that th attribute __f2py_numpy_version__ is present
# in the compiled module and that has the value np.__version__.
sources = [util.getpath("tests", "src", "regression", "inout.f90")]
@pytest.mark.slow
def test_numpy_version_attribute(self):
# Check that self.module has an attribute named "__f2py_numpy_version__"
assert hasattr(self.module, "__f2py_numpy_version__")
# Check that the attribute __f2py_numpy_version__ is a string
assert isinstance(self.module.__f2py_numpy_version__, str)
# Check that __f2py_numpy_version__ has the value numpy.__version__
assert np.__version__ == self.module.__f2py_numpy_version__
def test_include_path():
incdir = np.f2py.get_include()
fnames_in_dir = os.listdir(incdir)
for fname in ("fortranobject.c", "fortranobject.h"):
assert fname in fnames_in_dir
class TestModuleAndSubroutine(util.F2PyTest):
module_name = "example"
sources = [util.getpath("tests", "src", "regression", "gh25337", "data.f90"),
util.getpath("tests", "src", "regression", "gh25337", "use_data.f90")]
@pytest.mark.slow
def test_gh25337(self):
self.module.data.set_shift(3)
assert "data" in dir(self.module)
|