Skip to content

Commit 542974f

Browse files
committed
Add tests
1 parent 40105f0 commit 542974f

3 files changed

Lines changed: 56 additions & 0 deletions

File tree

test/fabscript

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,7 @@ python_version_major, python_version_minor = map(int, python.instance().version.
178178

179179
tests.append(extension_test("module_multi_phase",
180180
condition=python_version_major > 3 or (python_version_major == 3 and python_version_minor >= 5)))
181+
tests.append(extension_test("module_multi_phase_nogil",
182+
condition=python_version_major > 3 or (python_version_major == 3 and python_version_minor >= 5)))
181183

182184
default = report('report', tests, fail_on_failures=True)

test/module_multi_phase_nogil.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Test for BOOST_PYTHON_MODULE_MULTI_PHASE with optional mod_gil_not_used argument
2+
3+
#include <boost/python/module.hpp>
4+
#include <boost/python/def.hpp>
5+
6+
// Simple function to export
7+
int get_value() {
8+
return 1234;
9+
}
10+
11+
#if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x030D0000)
12+
// C++11 build with Python 3.13+: test with mod_gil_not_used option
13+
BOOST_PYTHON_MODULE_MULTI_PHASE(module_multi_phase_nogil_ext, boost::python::mod_gil_not_used())
14+
{
15+
using namespace boost::python;
16+
def("get_value", get_value);
17+
}
18+
#else
19+
// C++98 build or Python 3.12-: test without optional arguments
20+
BOOST_PYTHON_MODULE_MULTI_PHASE(module_multi_phase_nogil_ext)
21+
{
22+
using namespace boost::python;
23+
def("get_value", get_value);
24+
}
25+
#endif

test/module_multi_phase_nogil.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
>>> from module_multi_phase_nogil_ext import *
3+
>>> get_value()
4+
1234
5+
>>> import sys, sysconfig
6+
>>> Py_GIL_DISABLED = bool(sysconfig.get_config_var('Py_GIL_DISABLED'))
7+
>>> if Py_GIL_DISABLED and sys._is_gil_enabled():
8+
... print('GIL is enabled and should not be')
9+
... else:
10+
... print('okay')
11+
okay
12+
"""
13+
14+
from __future__ import print_function
15+
16+
def run(args = None):
17+
import sys
18+
import doctest
19+
20+
if args is not None:
21+
sys.argv = args
22+
return doctest.testmod(sys.modules.get(__name__))
23+
24+
if __name__ == '__main__':
25+
print("running...")
26+
import sys
27+
status = run()[0]
28+
if (status == 0): print("Done.")
29+
sys.exit(status)

0 commit comments

Comments
 (0)