44// http://www.boost.org/LICENSE_1_0.txt)
55
66#include < boost/python.hpp>
7+ #define BOOST_ENABLE_ASSERT_HANDLER 1
8+ #include < boost/assert.hpp>
79#include < iostream>
810
11+ namespace boost
12+ {
13+
14+ void assertion_failed (char const * expr, char const * function,
15+ char const * file, long line)
16+ {
17+ std::cerr << " assertion failed : " << expr << " in " << function
18+ << " at " << file << ' :' << line << std::endl;
19+ abort ();
20+ }
21+
22+ } // namespace boost
23+
924namespace python = boost::python;
1025
1126// An abstract base class
@@ -70,17 +85,15 @@ void exec_test()
7085
7186 // Creating and using instances of the C++ class is as easy as always.
7287 CppDerived cpp;
73- if (cpp.hello () != " Hello from C++!" )
74- throw std::runtime_error (" cpp.hello() returned unexpected string" );
88+ BOOST_ASSERT (cpp.hello () == " Hello from C++!" );
7589
7690 // But now creating and using instances of the Python class is almost
7791 // as easy!
7892 python::object py_base = PythonDerived ();
7993 Base& py = python::extract<Base&>(py_base) BOOST_EXTRACT_WORKAROUND;
8094
8195 // Make sure the right 'hello' method is called.
82- if (py.hello () != " Hello from Python!" )
83- throw std::runtime_error (" py.hello() returned unexpected string" );
96+ BOOST_ASSERT (py.hello () == " Hello from Python!" );
8497}
8598
8699void exec_file_test (std::string const &script)
@@ -90,8 +103,7 @@ void exec_file_test(std::string const &script)
90103 python::object result = python::exec_file (script.c_str (), global, global);
91104
92105 // Extract an object the script stored in the global dictionary.
93- if (python::extract<int >(global[" number" ]) != 42 )
94- throw std::runtime_error (" 'number' has unexpected value" );
106+ BOOST_ASSERT (python::extract<int >(global[" number" ]) == 42 );
95107}
96108
97109void exec_test_error ()
0 commit comments