Skip to content

Commit

Permalink
Migrate 'before_and_after27'.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-hof committed Jan 19, 2017
1 parent dac4060 commit 4d01d7e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 51 deletions.
51 changes: 0 additions & 51 deletions src/RestrictedPython/tests/before_and_after27.py

This file was deleted.

38 changes: 38 additions & 0 deletions tests/test_transformer.py
Expand Up @@ -1189,3 +1189,41 @@ def test_transformer_with_stmt_subscript(compile, mocker):

assert x == [0, 0, 1, 2, 0, 0, 0]
_write_.assert_called_once_with(x)


DICT_COMPREHENSION_WITH_ATTRS = """
def call(seq):
return {y.k: y.v for y in seq.z if y.k}
"""


@pytest.mark.parametrize(*compile)
def test_transformer_dict_comprehension_with_attrs(compile, mocker):
code, errors = compile(DICT_COMPREHENSION_WITH_ATTRS)[:2]

assert code is not None
assert errors == ()

_getattr_ = mocker.Mock()
_getattr_.side_effect = getattr

_getiter_ = mocker.Mock()
_getiter_.side_effect = lambda ob: ob

glb = {'_getattr_': _getattr_, '_getiter_': _getiter_}
six.exec_(code, glb)

z = [mocker.Mock(k=0, v='a'), mocker.Mock(k=1, v='b')]
seq = mocker.Mock(z=z)

ret = glb['call'](seq)
assert ret == {1: 'b'}

_getiter_.assert_called_once_with(z)
_getattr_.assert_has_calls([
mocker.call(seq, 'z'),
mocker.call(z[0], 'k'),
mocker.call(z[1], 'k'),
mocker.call(z[1], 'v'),
mocker.call(z[1], 'k')
])

0 comments on commit 4d01d7e

Please sign in to comment.