mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
test_eval: Show example of working closure (#2743)
* test_eval: Show example of working closure * Extend test_eval_closure with weirder examples of closures for py::eval Co-authored-by: Yannick Jadoul <yannick.jadoul@belgacom.net> Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
This commit is contained in:
@@ -33,3 +33,20 @@ def test_eval_empty_globals():
|
||||
g = {}
|
||||
assert "__builtins__" in m.eval_empty_globals(g)
|
||||
assert "__builtins__" in g
|
||||
|
||||
|
||||
def test_eval_closure():
|
||||
global_, local = m.test_eval_closure()
|
||||
|
||||
assert global_["closure_value"] == 42
|
||||
assert local["closure_value"] == 0
|
||||
|
||||
assert "local_value" not in global_
|
||||
assert local["local_value"] == 0
|
||||
|
||||
assert "func_global" not in global_
|
||||
assert local["func_global"]() == 42
|
||||
|
||||
assert "func_local" not in global_
|
||||
with pytest.raises(NameError):
|
||||
local["func_local"]()
|
||||
|
||||
Reference in New Issue
Block a user