Skip to content

Commit 763246a

Browse files
committed
Add test_with_boost_python/test_pickle_simple_callable:
See also: google/pybind11clif#30099
1 parent 587542f commit 763246a

File tree

4 files changed

+207
-0
lines changed

4 files changed

+207
-0
lines changed

test_with_boost_python/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ set(CMAKE_SHARED_MODULE_PREFIX "")
99
add_library(test_python_multiple_inheritance MODULE test_python_multiple_inheritance.cpp)
1010
target_link_libraries(test_python_multiple_inheritance ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
1111
target_include_directories(test_python_multiple_inheritance PRIVATE ${PYTHON_INCLUDE_DIRS})
12+
13+
add_library(test_pickle_simple_callable MODULE test_pickle_simple_callable.cpp)
14+
target_link_libraries(test_pickle_simple_callable ${Boost_LIBRARIES} ${PYTHON_LIBRARIES})
15+
target_include_directories(test_pickle_simple_callable PRIVATE ${PYTHON_INCLUDE_DIRS})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <boost/python.hpp>
2+
3+
namespace {
4+
5+
int simple_callable() { return 723; }
6+
7+
}
8+
9+
BOOST_PYTHON_MODULE(test_pickle_simple_callable) {
10+
namespace py = boost::python;
11+
12+
py::def("simple_callable", simple_callable);
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pickle
2+
3+
import pytest
4+
5+
from build import test_pickle_simple_callable as m
6+
7+
8+
def test_assumptions():
9+
assert pickle.HIGHEST_PROTOCOL >= 0
10+
11+
12+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
13+
def test_pickle_simple_callable(protocol):
14+
assert m.simple_callable() == 723
15+
serialized = pickle.dumps(m.simple_callable, protocol=protocol)
16+
assert b"test_pickle_simple_callable" in serialized
17+
assert b"simple_callable" in serialized
18+
deserialized = pickle.loads(serialized)
19+
assert deserialized() == 723
20+
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
-- The C compiler identification is GNU 13.2.0
2+
-- The CXX compiler identification is GNU 13.2.0
3+
-- Detecting C compiler ABI info
4+
-- Detecting C compiler ABI info - done
5+
-- Check for working C compiler: /usr/bin/cc - skipped
6+
-- Detecting C compile features
7+
-- Detecting C compile features - done
8+
-- Detecting CXX compiler ABI info
9+
-- Detecting CXX compiler ABI info - done
10+
-- Check for working CXX compiler: /usr/bin/c++ - skipped
11+
-- Detecting CXX compile features
12+
-- Detecting CXX compile features - done
13+
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.11.so (found version "3.11.6")
14+
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.74.0/BoostConfig.cmake (found version "1.74.0") found components: python
15+
-- Configuring done (0.4s)
16+
-- Generating done (0.0s)
17+
-- Build files have been written to: /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build
18+
/usr/bin/cmake -S/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python -B/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build --check-build-system CMakeFiles/Makefile.cmake 0
19+
/usr/bin/cmake -E cmake_progress_start /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build/CMakeFiles /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build//CMakeFiles/progress.marks
20+
make -f CMakeFiles/Makefile2 all
21+
make[1]: Entering directory '/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build'
22+
make -f CMakeFiles/test_pickle_simple_callable.dir/build.make CMakeFiles/test_pickle_simple_callable.dir/depend
23+
make[2]: Entering directory '/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build'
24+
cd /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build/CMakeFiles/test_pickle_simple_callable.dir/DependInfo.cmake "--color="
25+
make[2]: Leaving directory '/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build'
26+
make -f CMakeFiles/test_pickle_simple_callable.dir/build.make CMakeFiles/test_pickle_simple_callable.dir/build
27+
make[2]: Entering directory '/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build'
28+
[ 50%] Building CXX object CMakeFiles/test_pickle_simple_callable.dir/test_pickle_simple_callable.cpp.o
29+
/usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_PYTHON_DYN_LINK -Dtest_pickle_simple_callable_EXPORTS -I/usr/include/python3.11 -fPIC -MD -MT CMakeFiles/test_pickle_simple_callable.dir/test_pickle_simple_callable.cpp.o -MF CMakeFiles/test_pickle_simple_callable.dir/test_pickle_simple_callable.cpp.o.d -o CMakeFiles/test_pickle_simple_callable.dir/test_pickle_simple_callable.cpp.o -c /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/test_pickle_simple_callable.cpp
30+
[100%] Linking CXX shared module test_pickle_simple_callable.so
31+
/usr/bin/cmake -E cmake_link_script CMakeFiles/test_pickle_simple_callable.dir/link.txt --verbose=1
32+
/usr/bin/c++ -fPIC -shared -o test_pickle_simple_callable.so CMakeFiles/test_pickle_simple_callable.dir/test_pickle_simple_callable.cpp.o /usr/lib/x86_64-linux-gnu/libboost_python311.so.1.74.0 /usr/lib/x86_64-linux-gnu/libpython3.11.so
33+
make[2]: Leaving directory '/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build'
34+
[100%] Built target test_pickle_simple_callable
35+
make[1]: Leaving directory '/usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build'
36+
/usr/bin/cmake -E cmake_progress_start /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python/build/CMakeFiles 0
37+
============================= test session starts ==============================
38+
platform linux -- Python 3.11.6, pytest-7.4.3, pluggy-1.3.0 -- /usr/bin/python3
39+
cachedir: .pytest_cache
40+
rootdir: /usr/local/google/home/rwgk/clone/stuff/test_with_boost_python
41+
plugins: xdist-3.3.1
42+
collecting ... collected 7 items
43+
44+
test_pickle_simple_callable.py::test_assumptions PASSED [ 14%]
45+
test_pickle_simple_callable.py::test_pickle_simple_callable[0] FAILED [ 28%]
46+
test_pickle_simple_callable.py::test_pickle_simple_callable[1] FAILED [ 42%]
47+
test_pickle_simple_callable.py::test_pickle_simple_callable[2] FAILED [ 57%]
48+
test_pickle_simple_callable.py::test_pickle_simple_callable[3] FAILED [ 71%]
49+
test_pickle_simple_callable.py::test_pickle_simple_callable[4] FAILED [ 85%]
50+
test_pickle_simple_callable.py::test_pickle_simple_callable[5] FAILED [100%]
51+
52+
=================================== FAILURES ===================================
53+
________________________ test_pickle_simple_callable[0] ________________________
54+
55+
protocol = 0
56+
57+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
58+
def test_pickle_simple_callable(protocol):
59+
assert m.simple_callable() == 723
60+
> serialized = pickle.dumps(m.simple_callable, protocol=protocol)
61+
62+
test_pickle_simple_callable.py:15:
63+
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
64+
65+
self = <Boost.Python.function object at 0x2091970>, proto = 0
66+
67+
def _reduce_ex(self, proto):
68+
assert proto < 2
69+
cls = self.__class__
70+
for base in cls.__mro__:
71+
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
72+
break
73+
new = base.__new__
74+
if isinstance(new, _new_type) and new.__self__ is base:
75+
break
76+
else:
77+
base = object # not really reachable
78+
if base is object:
79+
state = None
80+
else:
81+
if base is cls:
82+
> raise TypeError(f"cannot pickle {cls.__name__!r} object")
83+
E TypeError: cannot pickle 'builtin_function_or_method' object
84+
85+
/usr/lib/python3.11/copyreg.py:76: TypeError
86+
________________________ test_pickle_simple_callable[1] ________________________
87+
88+
protocol = 1
89+
90+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
91+
def test_pickle_simple_callable(protocol):
92+
assert m.simple_callable() == 723
93+
> serialized = pickle.dumps(m.simple_callable, protocol=protocol)
94+
95+
test_pickle_simple_callable.py:15:
96+
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
97+
98+
self = <Boost.Python.function object at 0x2091970>, proto = 1
99+
100+
def _reduce_ex(self, proto):
101+
assert proto < 2
102+
cls = self.__class__
103+
for base in cls.__mro__:
104+
if hasattr(base, '__flags__') and not base.__flags__ & _HEAPTYPE:
105+
break
106+
new = base.__new__
107+
if isinstance(new, _new_type) and new.__self__ is base:
108+
break
109+
else:
110+
base = object # not really reachable
111+
if base is object:
112+
state = None
113+
else:
114+
if base is cls:
115+
> raise TypeError(f"cannot pickle {cls.__name__!r} object")
116+
E TypeError: cannot pickle 'builtin_function_or_method' object
117+
118+
/usr/lib/python3.11/copyreg.py:76: TypeError
119+
________________________ test_pickle_simple_callable[2] ________________________
120+
121+
protocol = 2
122+
123+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
124+
def test_pickle_simple_callable(protocol):
125+
assert m.simple_callable() == 723
126+
> serialized = pickle.dumps(m.simple_callable, protocol=protocol)
127+
E TypeError: cannot pickle 'Boost.Python.function' object
128+
129+
test_pickle_simple_callable.py:15: TypeError
130+
________________________ test_pickle_simple_callable[3] ________________________
131+
132+
protocol = 3
133+
134+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
135+
def test_pickle_simple_callable(protocol):
136+
assert m.simple_callable() == 723
137+
> serialized = pickle.dumps(m.simple_callable, protocol=protocol)
138+
E TypeError: cannot pickle 'Boost.Python.function' object
139+
140+
test_pickle_simple_callable.py:15: TypeError
141+
________________________ test_pickle_simple_callable[4] ________________________
142+
143+
protocol = 4
144+
145+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
146+
def test_pickle_simple_callable(protocol):
147+
assert m.simple_callable() == 723
148+
> serialized = pickle.dumps(m.simple_callable, protocol=protocol)
149+
E TypeError: cannot pickle 'Boost.Python.function' object
150+
151+
test_pickle_simple_callable.py:15: TypeError
152+
________________________ test_pickle_simple_callable[5] ________________________
153+
154+
protocol = 5
155+
156+
@pytest.mark.parametrize("protocol", range(pickle.HIGHEST_PROTOCOL + 1))
157+
def test_pickle_simple_callable(protocol):
158+
assert m.simple_callable() == 723
159+
> serialized = pickle.dumps(m.simple_callable, protocol=protocol)
160+
E TypeError: cannot pickle 'Boost.Python.function' object
161+
162+
test_pickle_simple_callable.py:15: TypeError
163+
=========================== short test summary info ============================
164+
FAILED test_pickle_simple_callable.py::test_pickle_simple_callable[0] - TypeE...
165+
FAILED test_pickle_simple_callable.py::test_pickle_simple_callable[1] - TypeE...
166+
FAILED test_pickle_simple_callable.py::test_pickle_simple_callable[2] - TypeE...
167+
FAILED test_pickle_simple_callable.py::test_pickle_simple_callable[3] - TypeE...
168+
FAILED test_pickle_simple_callable.py::test_pickle_simple_callable[4] - TypeE...
169+
FAILED test_pickle_simple_callable.py::test_pickle_simple_callable[5] - TypeE...
170+
========================= 6 failed, 1 passed in 0.03s ==========================

0 commit comments

Comments
 (0)