μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
test_eval.py
Go to the documentation of this file.
1import os
2
3import pytest
4
5import env # noqa: F401
6from pybind11_tests import eval_ as m
7
8
9def test_evals(capture):
10 with capture:
11 assert m.test_eval_statements()
12 assert capture == "Hello World!"
13
14 assert m.test_eval()
15 assert m.test_eval_single_statement()
16
17 assert m.test_eval_failure()
18
19
20@pytest.mark.xfail("env.PYPY", raises=RuntimeError)
21def test_eval_file():
22 filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py")
23 assert m.test_eval_file(filename)
24
25 assert m.test_eval_file_failure()
26
27
28def test_eval_empty_globals():
29 assert "__builtins__" in m.eval_empty_globals(None)
30
31 g = {}
32 assert "__builtins__" in m.eval_empty_globals(g)
33 assert "__builtins__" in g
34
35
36def test_eval_closure():
37 global_, local = m.test_eval_closure()
38
39 assert global_["closure_value"] == 42
40 assert local["closure_value"] == 0
41
42 assert "local_value" not in global_
43 assert local["local_value"] == 0
44
45 assert "func_global" not in global_
46 assert local["func_global"]() == 42
47
48 assert "func_local" not in global_
49 with pytest.raises(NameError):
50 local["func_local"]()