aboutsummaryrefslogtreecommitdiffstats
path: root/3rdparty/pybind11/tests/test_eval.cpp
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2022-09-14 09:28:47 +0200
committergatecat <gatecat@ds0.me>2022-09-14 09:28:47 +0200
commita72f898ff4c4237424c468044a6db9d6953b541e (patch)
tree1c4a543f661dd1b281aecf4660388491702fa8d8 /3rdparty/pybind11/tests/test_eval.cpp
parentf1349e114f3a16ccd002e8513339e18f5be4d31b (diff)
downloadnextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.tar.gz
nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.tar.bz2
nextpnr-a72f898ff4c4237424c468044a6db9d6953b541e.zip
3rdparty: Bump vendored pybind11 version for py3.11 support
Signed-off-by: gatecat <gatecat@ds0.me>
Diffstat (limited to '3rdparty/pybind11/tests/test_eval.cpp')
-rw-r--r--3rdparty/pybind11/tests/test_eval.cpp53
1 files changed, 36 insertions, 17 deletions
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 <pybind11/eval.h>
+
#include "pybind11_tests.h"
+#include <utility>
+
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<int>();
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<py::eval_single_statement>("x = call_test()", py::dict(), local);
auto x = local["x"].cast<int>();
@@ -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);
+ });
}