From a72f898ff4c4237424c468044a6db9d6953b541e Mon Sep 17 00:00:00 2001 From: gatecat Date: Wed, 14 Sep 2022 09:28:47 +0200 Subject: 3rdparty: Bump vendored pybind11 version for py3.11 support Signed-off-by: gatecat --- 3rdparty/pybind11/tests/test_eval.cpp | 53 ++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 17 deletions(-) (limited to '3rdparty/pybind11/tests/test_eval.cpp') diff --git a/3rdparty/pybind11/tests/test_eval.cpp b/3rdparty/pybind11/tests/test_eval.cpp index 5416c2ec..cd2903f0 100644 --- a/3rdparty/pybind11/tests/test_eval.cpp +++ b/3rdparty/pybind11/tests/test_eval.cpp @@ -7,10 +7,12 @@ BSD-style license that can be found in the LICENSE file. */ - #include + #include "pybind11_tests.h" +#include + TEST_SUBMODULE(eval_, m) { // test_evals @@ -18,16 +20,13 @@ TEST_SUBMODULE(eval_, m) { m.def("test_eval_statements", [global]() { auto local = py::dict(); - local["call_test"] = py::cpp_function([&]() -> int { - return 42; - }); + local["call_test"] = py::cpp_function([&]() -> int { return 42; }); // Regular string literal - py::exec( - "message = 'Hello World!'\n" - "x = call_test()", - global, local - ); + py::exec("message = 'Hello World!'\n" + "x = call_test()", + global, + local); // Multi-line raw string literal py::exec(R"( @@ -35,8 +34,9 @@ TEST_SUBMODULE(eval_, m) { print(message) else: raise RuntimeError - )", global, local - ); + )", + global, + local); auto x = local["x"].cast(); return x == 42; @@ -51,9 +51,7 @@ TEST_SUBMODULE(eval_, m) { m.def("test_eval_single_statement", []() { auto local = py::dict(); - local["call_test"] = py::cpp_function([&]() -> int { - return 42; - }); + local["call_test"] = py::cpp_function([&]() -> int { return 42; }); auto result = py::eval("x = call_test()", py::dict(), local); auto x = local["x"].cast(); @@ -64,10 +62,10 @@ TEST_SUBMODULE(eval_, m) { auto local = py::dict(); local["y"] = py::int_(43); - int val_out; + int val_out = 0; local["call_test2"] = py::cpp_function([&](int value) { val_out = value; }); - auto result = py::eval_file(filename, global, local); + auto result = py::eval_file(std::move(filename), global, local); return val_out == 43 && result.is_none(); }); @@ -91,9 +89,30 @@ TEST_SUBMODULE(eval_, m) { // test_eval_empty_globals m.def("eval_empty_globals", [](py::object global) { - if (global.is_none()) + if (global.is_none()) { global = py::dict(); + } auto int_class = py::eval("isinstance(42, int)", global); return global; }); + + // test_eval_closure + m.def("test_eval_closure", []() { + py::dict global; + global["closure_value"] = 42; + py::dict local; + local["closure_value"] = 0; + py::exec(R"( + local_value = closure_value + + def func_global(): + return closure_value + + def func_local(): + return local_value + )", + global, + local); + return std::make_pair(global, local); + }); } -- cgit v1.2.3