m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.8 KiB

6 months ago
  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__)
  34. def test_include_path():
  35. incdir = np.f2py.get_include()
  36. fnames_in_dir = os.listdir(incdir)
  37. for fname in ('fortranobject.c', 'fortranobject.h'):
  38. assert fname in fnames_in_dir