summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSebastian Berg <sebastian@sipsolutions.net>2020-06-18 15:04:02 -0500
committerGitHub <noreply@github.com>2020-06-18 15:04:02 -0500
commita69ce0652b27b55d680a9d6def2a05c4376653c9 (patch)
tree22e3559c6b6fb052d9feb24981f6fdb1cf82be6b /numpy
parenteb22fe8f82b8c7b0561b25614cb0863b71b4427a (diff)
parent908d865712d423dcd6117929fca463c1708dc702 (diff)
downloadnumpy-a69ce0652b27b55d680a9d6def2a05c4376653c9.tar.gz
Merge pull request #16594 from sturlamolden/f2py-version-fix2
ENH: Add __f2py_numpy_version__ attribute to Fortran modules.
Diffstat (limited to 'numpy')
-rwxr-xr-xnumpy/f2py/rules.py6
-rw-r--r--numpy/f2py/tests/test_regression.py22
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__)