Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:53

0001 import os
0002 
0003 import pytest
0004 
0005 import env  # noqa: F401
0006 from pybind11_tests import eval_ as m
0007 
0008 
0009 def test_evals(capture):
0010     with capture:
0011         assert m.test_eval_statements()
0012     assert capture == "Hello World!"
0013 
0014     assert m.test_eval()
0015     assert m.test_eval_single_statement()
0016 
0017     assert m.test_eval_failure()
0018 
0019 
0020 @pytest.mark.xfail("env.PYPY", raises=RuntimeError)
0021 def test_eval_file():
0022     filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py")
0023     assert m.test_eval_file(filename)
0024 
0025     assert m.test_eval_file_failure()
0026 
0027 
0028 def test_eval_empty_globals():
0029     assert "__builtins__" in m.eval_empty_globals(None)
0030 
0031     g = {}
0032     assert "__builtins__" in m.eval_empty_globals(g)
0033     assert "__builtins__" in g
0034 
0035 
0036 def test_eval_closure():
0037     global_, local = m.test_eval_closure()
0038 
0039     assert global_["closure_value"] == 42
0040     assert local["closure_value"] == 0
0041 
0042     assert "local_value" not in global_
0043     assert local["local_value"] == 0
0044 
0045     assert "func_global" not in global_
0046     assert local["func_global"]() == 42
0047 
0048     assert "func_local" not in global_
0049     with pytest.raises(NameError):
0050         local["func_local"]()