Skip to content

Commit 699aee5

Browse files
author
Daniel Jacobs
committed
add unit test for default python configuration
1 parent b91d98e commit 699aee5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_embed/test_interpreter.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,22 @@ TEST_CASE("Custom PyConfig with argv") {
197197
const auto &cpp_widget = py_widget.cast<const Widget &>();
198198
REQUIRE(cpp_widget.argv0() == "a.out");
199199
}
200+
201+
{
202+
PyConfig config;
203+
PyConfig_InitPythonConfig(&config);
204+
205+
// Parse arguments the way python normally does, and strip the first argument (which is
206+
// expected to be "python")
207+
char *argv[] = {strdup("python"), strdup("a.out")};
208+
py::scoped_interpreter argv_scope(&config, 2, argv);
209+
std::free(argv[0]);
210+
std::free(argv[1]);
211+
auto module = py::module::import("test_interpreter");
212+
auto py_widget = module.attr("DerivedWidget")("The question");
213+
const auto &cpp_widget = py_widget.cast<const Widget &>();
214+
REQUIRE(cpp_widget.argv0() == "a.out");
215+
}
200216
py::initialize_interpreter();
201217
}
202218
#endif

0 commit comments

Comments
 (0)