File: test_eval_exec.py

package info (click to toggle)
restrictedpython 8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,576 kB
  • sloc: python: 4,120; makefile: 193
file content (25 lines) | stat: -rw-r--r-- 653 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from RestrictedPython import compile_restricted_exec


EXEC_FUNCTION = """\
def no_exec():
    exec('q = 1')
"""


def test_RestrictingNodeTransformer__visit_Exec__2():
    """It is an error if the code call the `exec` function."""
    result = compile_restricted_exec(EXEC_FUNCTION)
    assert result.errors == ("Line 2: Exec calls are not allowed.",)


EVAL_FUNCTION = """\
def no_eval():
    eval('q = 1')
"""


def test_RestrictingNodeTransformer__visit_Eval__1():
    """It is an error if the code call the `eval` function."""
    result = compile_restricted_exec(EVAL_FUNCTION)
    assert result.errors == ("Line 2: Eval calls are not allowed.",)