File: test_loop.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 (45 lines) | stat: -rw-r--r-- 754 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from tests.helper import restricted_exec


WHILE = """\
a = 5
while a < 7:
    a = a + 3
"""


def test_RestrictingNodeTransformer__visit_While__1():
    """It allows `while` statements."""
    glb = restricted_exec(WHILE)
    assert glb['a'] == 8


BREAK = """\
a = 5
while True:
    a = a + 3
    if a >= 7:
        break
"""


def test_RestrictingNodeTransformer__visit_Break__1():
    """It allows `break` statements."""
    glb = restricted_exec(BREAK)
    assert glb['a'] == 8


CONTINUE = """\
a = 3
while a < 10:
    if a < 5:
        a = a + 1
        continue
    a = a + 10
"""


def test_RestrictingNodeTransformer__visit_Continue__1():
    """It allows `continue` statements."""
    glb = restricted_exec(CONTINUE)
    assert glb['a'] == 15