Skip to content

Commit

Permalink
Port weird lambda test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed Feb 1, 2017
1 parent bef0f7f commit f124cf9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/RestrictedPython/tests/security_in_syntax.py
Expand Up @@ -3,11 +3,6 @@
# Each function in this module is compiled using compile_restricted().


def check_getattr_in_lambda(arg=lambda _getattr=(lambda ob, name: name):
_getattr):
42


def except_using_bad_name():
try:
foo
Expand Down
16 changes: 16 additions & 0 deletions tests/test_transformer.py
Expand Up @@ -988,6 +988,22 @@ def test_transformer__RestrictingNodeTransformer__visit_Lambda__7(compile):
assert code is None


BAD_ARG_IN_LAMBDA = """\
def check_getattr_in_lambda(arg=lambda _bad=(lambda ob, name: name): _bad2):
42
"""


@pytest.mark.parametrize(*compile)
def test_transformer__RestrictingNodeTransformer__visit_Lambda__8(compile):
"""It prevents arguments starting with `_` in weird lambdas."""
code, errors = compile(BAD_ARG_IN_LAMBDA)[:2]
# RestrictedPython.compile.compile_restricted_exec finds both invalid
# names, while the old implementation seems to abort after the first.
assert lambda_err_msg in errors
assert code is None


@pytest.mark.skipif(
IS_PY3,
reason="tuple parameter unpacking is gone in python 3")
Expand Down

0 comments on commit f124cf9

Please sign in to comment.