Skip to content

Commit

Permalink
add unit test for default python configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Jacobs committed Jan 28, 2023
1 parent b91d98e commit 699aee5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_embed/test_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,22 @@ TEST_CASE("Custom PyConfig with argv") {
const auto &cpp_widget = py_widget.cast<const Widget &>();
REQUIRE(cpp_widget.argv0() == "a.out");
}

{
PyConfig config;
PyConfig_InitPythonConfig(&config);

// Parse arguments the way python normally does, and strip the first argument (which is
// expected to be "python")
char *argv[] = {strdup("python"), strdup("a.out")};
py::scoped_interpreter argv_scope(&config, 2, argv);
std::free(argv[0]);
std::free(argv[1]);
auto module = py::module::import("test_interpreter");
auto py_widget = module.attr("DerivedWidget")("The question");
const auto &cpp_widget = py_widget.cast<const Widget &>();
REQUIRE(cpp_widget.argv0() == "a.out");
}
py::initialize_interpreter();
}
#endif
Expand Down

0 comments on commit 699aee5

Please sign in to comment.