test_eval.py 828 Bytes
Newer Older
1
# -*- coding: utf-8 -*-
2
import os
3

Isuru Fernando's avatar
Isuru Fernando committed
4
import pytest
5
6
7

import env  # noqa: F401

8
from pybind11_tests import eval_ as m
Dean Moldovan's avatar
Dean Moldovan committed
9
10


11
def test_evals(capture):
Dean Moldovan's avatar
Dean Moldovan committed
12
    with capture:
13
        assert m.test_eval_statements()
14
15
    assert capture == "Hello World!"

16
17
    assert m.test_eval()
    assert m.test_eval_single_statement()
18

Isuru Fernando's avatar
Isuru Fernando committed
19
20
21
    assert m.test_eval_failure()


22
@pytest.mark.xfail("env.PYPY and not env.PY2", raises=RuntimeError)
Isuru Fernando's avatar
Isuru Fernando committed
23
def test_eval_file():
24
    filename = os.path.join(os.path.dirname(__file__), "test_eval_call.py")
25
    if env.PY2:
26
        filename = filename.decode("utf-8")
27
    assert m.test_eval_file(filename)
28

29
    assert m.test_eval_file_failure()
30
31
32
33
34
35
36
37


def test_eval_empty_globals():
    assert "__builtins__" in m.eval_empty_globals(None)

    g = {}
    assert "__builtins__" in m.eval_empty_globals(g)
    assert "__builtins__" in g