Skip to content

Commit

Permalink
Merge branch 'master' into better_message_for_range_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
loechel committed Oct 2, 2018
2 parents e07dec6 + 4f56542 commit e11c7c2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/test_iterating_over_dict_items.py
@@ -0,0 +1,35 @@
from RestrictedPython import safe_builtins
from RestrictedPython.Eval import default_guarded_getiter
from RestrictedPython.Guards import guarded_iter_unpack_sequence
from tests import c_exec

import pytest


ITERATE_OVER_DICT_ITEMS = """
d = {'a': 'b'}
for k, v in d.items():
pass
"""


@pytest.mark.parametrize(*c_exec)
def test_iterate_over_dict_items_plain(c_exec):
glb = {}
result = c_exec(ITERATE_OVER_DICT_ITEMS)
assert result.code is not None
assert result.errors == ()
with pytest.raises(NameError) as excinfo:
exec(result.code, glb, None)
assert "name '_iter_unpack_sequence_' is not defined" in str(excinfo.value)


@pytest.mark.parametrize(*c_exec)
def test_iterate_over_dict_items_safe(c_exec):
glb = safe_builtins.copy()
glb['_getiter_'] = default_guarded_getiter
glb['_iter_unpack_sequence_'] = guarded_iter_unpack_sequence
result = c_exec(ITERATE_OVER_DICT_ITEMS)
assert result.code is not None
assert result.errors == ()
exec(result.code, glb, None)

0 comments on commit e11c7c2

Please sign in to comment.