Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Python3_update' into python3_usage_documentation
- Loading branch information
Showing
8 changed files
with
324 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ python: | |
- 3.4 | ||
- 3.5 | ||
- 3.6 | ||
- pypy | ||
- pypy-5.4 | ||
env: | ||
- ENVIRON=py | ||
- ENVIRON=isort | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from RestrictedPython._compat import IS_PY2 | ||
|
||
import RestrictedPython | ||
|
||
|
||
def _execute(compile_func): | ||
"""Factory to create an execute function.""" | ||
def _execute(source): | ||
code, errors = compile_func(source)[:2] | ||
assert errors == (), errors | ||
assert code is not None | ||
glb = {} | ||
exec(code, glb) | ||
return glb | ||
return _execute | ||
|
||
|
||
# Define the arguments for @pytest.mark.parametrize to be able to test both the | ||
# old and the new implementation to be equal: | ||
compile = ('compile', [RestrictedPython.compile.compile_restricted_exec]) | ||
execute = ('execute', | ||
[_execute(RestrictedPython.compile.compile_restricted_exec)]) | ||
if IS_PY2: | ||
from RestrictedPython import RCompile | ||
compile[1].append(RCompile.compile_restricted_exec) | ||
execute[1].append(_execute(RCompile.compile_restricted_exec)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from . import compile | ||
from RestrictedPython._compat import IS_PY2 | ||
|
||
import pytest | ||
|
||
|
||
EXEC_STATEMENT = """\ | ||
def no_exec(): | ||
exec 'q = 1' | ||
""" | ||
|
||
|
||
@pytest.mark.skipif( | ||
IS_PY2, | ||
reason="exec statement in Python 2 is handled by RestrictedPython ") | ||
@pytest.mark.parametrize(*compile) | ||
def test_compile__compile_restricted_exec__10(compile): | ||
"""It is a SyntaxError to use the `exec` statement. (Python 3 only)""" | ||
code, errors, warnings, used_names = compile(EXEC_STATEMENT) | ||
assert ( | ||
"Line 2: SyntaxError: Missing parentheses in call to 'exec' in on " | ||
"statement: exec 'q = 1'",) == errors |
Oops, something went wrong.