Skip to content

Commit

Permalink
Add a unittest for unpack sequence with starred elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-hof authored and Michael Howitz committed Nov 9, 2016
1 parent 5281ecb commit 537cba1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,35 @@ def test_transformer__RestrictingNodeTransformer__visit_Assign(compile, mocker):
_getiter_.reset_mock()


@pytest.mark.skipif(
sys.version_info.major == 2,
reason="starred assignments are python3 only")
@pytest.mark.parametrize(*compile)
def test_transformer__RestrictingNodeTransformer__visit_Assign2(compile, mocker):
src = "a, *d, (c, *e), x = (1, 2, 3, (4, 3, 4), 5)"
code, errors = compile(src)[:2]

_getiter_ = mocker.stub()
_getiter_.side_effect = lambda it: it

glb = {
'_getiter_': _getiter_,
'_unpack_sequence_': guarded_unpack_sequence
}

six.exec_(code, glb)

assert glb['a'] == 1
assert glb['d'] == [2, 3]
assert glb['c'] == 4
assert glb['e'] == [3, 4]
assert glb['x'] == 5

_getiter_.assert_has_calls([
mocker.call((1, 2, 3, (4, 3, 4), 5)),
mocker.call((4, 3, 4))])


TRY_EXCEPT_FINALLY = """
def try_except(m):
try:
Expand Down

0 comments on commit 537cba1

Please sign in to comment.