diff options
author | myrtle <gatecat@ds0.me> | 2022-09-15 09:06:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-15 09:06:35 +0200 |
commit | 3983d4fe53e2c609a5c76510aff8e998a4c22285 (patch) | |
tree | 1c4a543f661dd1b281aecf4660388491702fa8d8 /3rdparty/pybind11/tests/test_eval.cpp | |
parent | f1349e114f3a16ccd002e8513339e18f5be4d31b (diff) | |
parent | a72f898ff4c4237424c468044a6db9d6953b541e (diff) | |
download | nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.tar.gz nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.tar.bz2 nextpnr-3983d4fe53e2c609a5c76510aff8e998a4c22285.zip |
Merge pull request #1024 from YosysHQ/gatecat/pybind11-bump
3rdparty: Bump vendored pybind11 version for py3.11 support
Diffstat (limited to '3rdparty/pybind11/tests/test_eval.cpp')
-rw-r--r-- | 3rdparty/pybind11/tests/test_eval.cpp | 53 |
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); + }); } |