17 auto global =
py::dict(py::module::import(
"__main__").attr(
"__dict__"));
19 m.def(
"test_eval_statements", [global]() {
27 "message = 'Hello World!'\n" 40 auto x = local[
"x"].cast<
int>();
45 m.def(
"test_eval", [global]() {
49 return x.cast<
int>() == 42;
52 m.def(
"test_eval_single_statement", []() {
58 auto result = py::eval<py::eval_single_statement>(
"x = call_test()",
py::dict(), local);
59 auto x = local[
"x"].cast<
int>();
60 return result.
is_none() && x == 42;
63 m.def(
"test_eval_file", [global](
py::str filename) {
71 return val_out == 43 && result.
is_none();
74 m.def(
"test_eval_failure", []() {
83 m.def(
"test_eval_file_failure", []() {
86 }
catch (std::exception &) {
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
void exec(str expr, object global=globals(), object local=object())
bool is_none() const
Equivalent to obj is None in Python.
op_< op_int, op_u, self_t, undefined_t > int_(const self_t &)
object eval_file(str fname, object global=globals(), object local=object())
object eval(str expr, object global=globals(), object local=object())
test_initializer eval_("eval_", test_submodule_eval_)
#define TEST_SUBMODULE(name, variable)