test_regression.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import os
  2. import pytest
  3. import numpy as np
  4. from . import util
  5. class TestIntentInOut(util.F2PyTest):
  6. # Check that intent(in out) translates as intent(inout)
  7. sources = [util.getpath("tests", "src", "regression", "inout.f90")]
  8. @pytest.mark.slow
  9. def test_inout(self):
  10. # non-contiguous should raise error
  11. x = np.arange(6, dtype=np.float32)[::2]
  12. pytest.raises(ValueError, self.module.foo, x)
  13. # check values with contiguous array
  14. x = np.arange(3, dtype=np.float32)
  15. self.module.foo(x)
  16. assert np.allclose(x, [3, 1, 2])
  17. class TestNegativeBounds(util.F2PyTest):
  18. # Check that negative bounds work correctly
  19. sources = [util.getpath("tests", "src", "negative_bounds", "issue_20853.f90")]
  20. @pytest.mark.slow
  21. def test_negbound(self):
  22. xvec = np.arange(12)
  23. xlow = -6
  24. xhigh = 4
  25. # Calculate the upper bound,
  26. # Keeping the 1 index in mind
  27. def ubound(xl, xh):
  28. return xh - xl + 1
  29. rval = self.module.foo(is_=xlow, ie_=xhigh,
  30. arr=xvec[:ubound(xlow, xhigh)])
  31. expval = np.arange(11, dtype = np.float32)
  32. assert np.allclose(rval, expval)
  33. class TestNumpyVersionAttribute(util.F2PyTest):
  34. # Check that th attribute __f2py_numpy_version__ is present
  35. # in the compiled module and that has the value np.__version__.
  36. sources = [util.getpath("tests", "src", "regression", "inout.f90")]
  37. @pytest.mark.slow
  38. def test_numpy_version_attribute(self):
  39. # Check that self.module has an attribute named "__f2py_numpy_version__"
  40. assert hasattr(self.module, "__f2py_numpy_version__")
  41. # Check that the attribute __f2py_numpy_version__ is a string
  42. assert isinstance(self.module.__f2py_numpy_version__, str)
  43. # Check that __f2py_numpy_version__ has the value numpy.__version__
  44. assert np.__version__ == self.module.__f2py_numpy_version__
  45. def test_include_path():
  46. incdir = np.f2py.get_include()
  47. fnames_in_dir = os.listdir(incdir)
  48. for fname in ("fortranobject.c", "fortranobject.h"):
  49. assert fname in fnames_in_dir