diff options
author | Sturla Molden <sturla@molden.no> | 2020-06-16 03:35:26 +0200 |
---|---|---|
committer | Sturla Molden <sturla@molden.no> | 2020-06-17 07:56:50 +0200 |
commit | 908d865712d423dcd6117929fca463c1708dc702 (patch) | |
tree | 87d18d0f7d27877b017b8fd307f1eca96916f400 /numpy | |
parent | 1fb7047b0ceba98d43b50ebb398be899ff8f6a1c (diff) | |
download | numpy-908d865712d423dcd6117929fca463c1708dc702.tar.gz |
add __f2py_numpy_version__ attribute
Diffstat (limited to 'numpy')
-rwxr-xr-x | numpy/f2py/rules.py | 6 | ||||
-rw-r--r-- | numpy/f2py/tests/test_regression.py | 22 |
2 files changed, 27 insertions, 1 deletions
diff --git a/numpy/f2py/rules.py b/numpy/f2py/rules.py index 7b25b545a..56f2033ff 100755 --- a/numpy/f2py/rules.py +++ b/numpy/f2py/rules.py @@ -55,6 +55,9 @@ __version__ = "$Revision: 1.129 $"[10:-1] from . import __version__ f2py_version = __version__.version +from .. import version as _numpy_version +numpy_version = _numpy_version.version + import os import time import copy @@ -206,6 +209,9 @@ PyMODINIT_FUNC PyInit_#modulename#(void) { \t\t\"This module '#modulename#' is auto-generated with f2py (version:#f2py_version#).\\nFunctions:\\n\"\n#docs#\".\"); \tPyDict_SetItemString(d, \"__doc__\", s); \tPy_DECREF(s); +\ts = PyUnicode_FromString(\"""" + numpy_version + """\"); +\tPyDict_SetItemString(d, \"__f2py_numpy_version__\", s); +\tPy_DECREF(s); \t#modulename#_error = PyErr_NewException (\"#modulename#.error\", NULL, NULL); \t/* \t * Store the error object inside the dict, so that it could get deallocated. diff --git a/numpy/f2py/tests/test_regression.py b/numpy/f2py/tests/test_regression.py index 67e00f1f7..a1b772069 100644 --- a/numpy/f2py/tests/test_regression.py +++ b/numpy/f2py/tests/test_regression.py @@ -2,7 +2,7 @@ import os import pytest import numpy as np -from numpy.testing import assert_raises, assert_equal +from numpy.testing import assert_, assert_raises, assert_equal, assert_string_equal from . import util @@ -25,3 +25,23 @@ class TestIntentInOut(util.F2PyTest): x = np.arange(3, dtype=np.float32) self.module.foo(x) assert_equal(x, [3, 1, 2]) + + +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 = [_path('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__"), + msg="Fortran module does not have __f2py_numpy_version__") + + # Check that the attribute __f2py_numpy_version__ is a string + assert_(isinstance(self.module.__f2py_numpy_version__, str), + msg="__f2py_numpy_version__ is not a string") + + # Check that __f2py_numpy_version__ has the value numpy.__version__ + assert_string_equal(np.__version__, self.module.__f2py_numpy_version__) |