From 91e323f194df09dfd5822d2ae9562767f0c30e97 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 16 Aug 2023 18:04:18 +0200 Subject: [PATCH] Tests log the Python version --- tests/test_pythoncapi_compat.py | 18 ++++++++++++++++-- tests/test_pythoncapi_compat_cext.c | 26 ++++++++++++++++++-------- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/tests/test_pythoncapi_compat.py b/tests/test_pythoncapi_compat.py index b7f05bc..948906c 100644 --- a/tests/test_pythoncapi_compat.py +++ b/tests/test_pythoncapi_compat.py @@ -143,8 +143,22 @@ def run_tests(module_name, lang): print() return - if VERBOSE and hasattr(testmod, "__cplusplus"): - print("__cplusplus: %s" % testmod.__cplusplus) + if VERBOSE: + empty_line = False + for attr in ('__cplusplus', 'PY_VERSION', 'PY_VERSION_HEX', + 'PYPY_VERSION', 'PYPY_VERSION_NUM'): + try: + value = getattr(testmod, attr) + except AttributeError: + pass + else: + if attr in ("PY_VERSION_HEX", "PYPY_VERSION_NUM"): + value = "0x%x" % value + print("%s: %s" % (attr, value)) + empty_line = True + + if empty_line: + print() check_refleak = hasattr(sys, 'gettotalrefcount') diff --git a/tests/test_pythoncapi_compat_cext.c b/tests/test_pythoncapi_compat_cext.c index 5210495..13c0edf 100644 --- a/tests/test_pythoncapi_compat_cext.c +++ b/tests/test_pythoncapi_compat_cext.c @@ -1222,22 +1222,32 @@ static struct PyMethodDef methods[] = { }; -#ifdef __cplusplus static int module_exec(PyObject *module) { +#ifdef __cplusplus if (PyModule_AddIntMacro(module, __cplusplus)) { return -1; } +#endif + if (PyModule_AddStringMacro(module, PY_VERSION)) { + return -1; + } + if (PyModule_AddIntMacro(module, PY_VERSION_HEX)) { + return -1; + } +#ifdef PYPY_VERSION + if (PyModule_AddStringMacro(module, PYPY_VERSION)) { + return -1; + } +#endif +#ifdef PYPY_VERSION_NUM + if (PyModule_AddIntMacro(module, PYPY_VERSION_NUM)) { + return -1; + } +#endif return 0; } -#else -static int -module_exec(PyObject *Py_UNUSED(module)) -{ - return 0; -} -#endif #if PY_VERSION_HEX >= 0x03050000