Skip to content

Commit

Permalink
Merge pull request #333 from jcrist/pluck-default-test
Browse files Browse the repository at this point in the history
Add tests for pluck with default, non-None
  • Loading branch information
eriknw committed Oct 3, 2016
2 parents 68ede01 + 9ff94a3 commit 068d1d9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions toolz/tests/test_itertoolz.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,10 @@ def test_pluck():

data = [{'id': 1, 'name': 'cheese'}, {'id': 2, 'name': 'pies', 'price': 1}]
assert list(pluck('id', data)) == [1, 2]
assert list(pluck('price', data, None)) == [None, 1]
assert list(pluck('price', data, 0)) == [0, 1]
assert list(pluck(['id', 'name'], data)) == [(1, 'cheese'), (2, 'pies')]
assert list(pluck(['name'], data)) == [('cheese',), ('pies',)]
assert list(pluck(['price', 'other'], data, None)) == [(None, None),
(1, None)]
assert list(pluck(['price', 'other'], data, 0)) == [(0, 0), (1, 0)]

assert raises(IndexError, lambda: list(pluck(1, [[0]])))
assert raises(KeyError, lambda: list(pluck('name', [{'id': 1}])))
Expand Down

0 comments on commit 068d1d9

Please sign in to comment.