test_regression.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import pytest
  3. import numpy as np
  4. from numpy.testing import assert_, assert_raises, assert_equal, assert_string_equal
  5. from . import util
  6. def _path(*a):
  7. return os.path.join(*((os.path.dirname(__file__),) + a))
  8. class TestIntentInOut(util.F2PyTest):
  9. # Check that intent(in out) translates as intent(inout)
  10. sources = [_path('src', 'regression', 'inout.f90')]
  11. @pytest.mark.slow
  12. def test_inout(self):
  13. # non-contiguous should raise error
  14. x = np.arange(6, dtype=np.float32)[::2]
  15. assert_raises(ValueError, self.module.foo, x)
  16. # check values with contiguous array
  17. x = np.arange(3, dtype=np.float32)
  18. self.module.foo(x)
  19. assert_equal(x, [3, 1, 2])
  20. class TestNumpyVersionAttribute(util.F2PyTest):
  21. # Check that th attribute __f2py_numpy_version__ is present
  22. # in the compiled module and that has the value np.__version__.
  23. sources = [_path('src', 'regression', 'inout.f90')]
  24. @pytest.mark.slow
  25. def test_numpy_version_attribute(self):
  26. # Check that self.module has an attribute named "__f2py_numpy_version__"
  27. assert_(hasattr(self.module, "__f2py_numpy_version__"),
  28. msg="Fortran module does not have __f2py_numpy_version__")
  29. # Check that the attribute __f2py_numpy_version__ is a string
  30. assert_(isinstance(self.module.__f2py_numpy_version__, str),
  31. msg="__f2py_numpy_version__ is not a string")
  32. # Check that __f2py_numpy_version__ has the value numpy.__version__
  33. assert_string_equal(np.__version__, self.module.__f2py_numpy_version__)