Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make tests pass, by adapting functionality from old implementation by…
… allowing operations / statements in new implementation
- Loading branch information
Showing
3 changed files
with
66 additions
and
55 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
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 |
---|---|---|
@@ -1,37 +1,55 @@ | ||
from RestrictedPython._compat import IS_PY3 | ||
from tests import c_exec | ||
|
||
import pytest | ||
|
||
|
||
GLOBAL_EXAMPLE = """ | ||
a = 1 | ||
global a | ||
a = 1 | ||
""" | ||
|
||
|
||
@pytest.mark.parametrize(*c_exec) | ||
def test_Global(c_exec): | ||
result = c_exec(GLOBAL_EXAMPLE) | ||
assert result.code is None | ||
assert result.errors == ( | ||
'Line 3: Global statements are not allowed.', | ||
) | ||
assert result.code is not None | ||
assert result.errors == () | ||
assert result.warnings == [] | ||
assert result.used_names == {} | ||
|
||
|
||
# Example from: | ||
# https://www.smallsurething.com/a-quick-guide-to-nonlocal-in-python-3/ | ||
NONLOCAL_EXAMPLE = """ | ||
a = 1 | ||
nonlocal a | ||
def outside(): | ||
msg = "Outside!" | ||
def inside(): | ||
nonlocal msg | ||
msg = "Inside!" | ||
print(msg) | ||
inside() | ||
print(msg) | ||
outside() | ||
""" | ||
|
||
|
||
@pytest.mark.skipif( | ||
not IS_PY3, | ||
reason="Nonlocal Statement was introducted on Python 3.0 but never in Python 2") # NOQA: E501 | ||
@pytest.mark.parametrize(*c_exec) | ||
def test_Nonlocal(c_exec): | ||
result = c_exec(NONLOCAL_EXAMPLE) | ||
assert result.code is None | ||
assert result.errors == ( | ||
'Line 3: Nonlocal statements are not allowed.', | ||
'Line 5: Nonlocal statements are not allowed.', | ||
) | ||
assert result.warnings == [] | ||
assert result.used_names == {} | ||
assert result.warnings == [ | ||
"Line 4: Prints, but never reads 'printed' variable.", | ||
"Line 2: Prints, but never reads 'printed' variable." | ||
] | ||
assert result.used_names == { | ||
'msg': True, | ||
'inside': True, | ||
'outside': True | ||
} |
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