Skip to content

Commit d738927

Browse files
author
Ralf W. Grosse-Kunstleve
committed
libs/python/test/exec.cpp: new exercise_embedding_html(), in reaction to https://svn.boost.org/trac/boost/ticket/1890
[SVN r55640]
1 parent 8d2ca93 commit d738927

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

test/exec.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ void exec_test_error()
108108
python::object result = python::exec("print unknown \n", global, global);
109109
}
110110

111+
void exercise_embedding_html()
112+
{
113+
using namespace boost::python;
114+
/* code from: libs/python/doc/tutorial/doc/tutorial.qbk
115+
(generates libs/python/doc/tutorial/doc/html/python/embedding.html)
116+
*/
117+
object main_module = import("__main__");
118+
object main_namespace = main_module.attr("__dict__");
119+
120+
object ignored = exec("hello = file('hello.txt', 'w')\n"
121+
"hello.write('Hello world!')\n"
122+
"hello.close()",
123+
main_namespace);
124+
}
125+
111126
void check_pyerr(bool pyerr_expected=false)
112127
{
113128
if (PyErr_Occurred())
@@ -129,7 +144,7 @@ void check_pyerr(bool pyerr_expected=false)
129144

130145
int main(int argc, char **argv)
131146
{
132-
BOOST_TEST(argc == 2);
147+
BOOST_TEST(argc == 2 || argc == 3);
133148
std::string script = argv[1];
134149
// Initialize the interpreter
135150
Py_Initialize();
@@ -152,7 +167,14 @@ int main(int argc, char **argv)
152167
{
153168
BOOST_ERROR("Python exception expected, but not seen.");
154169
}
155-
170+
171+
if (argc > 2) {
172+
// The main purpose is to test compilation. Since this test generates
173+
// a file and I (rwgk) am uncertain about the side-effects, run it only
174+
// if explicitly requested.
175+
exercise_embedding_html();
176+
}
177+
156178
// Boost.Python doesn't support Py_Finalize yet.
157179
// Py_Finalize();
158180
return boost::report_errors();

0 commit comments

Comments
 (0)