Skip to content

ENH: add __contains__ to Cycler object #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ def __init__(self, left, right=None, op=None):
self._keys = _process_keys(self._left, self._right)
self._op = op

def __contains__(self, k):
return k in self._keys

@property
def keys(self):
"""
Expand Down
15 changes: 15 additions & 0 deletions test_cycler.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,18 @@ def test_by_key_mul():
assert_equal(input_dict['lw'] * len(input_dict['c']),
res['lw'])
yield _by_key_helper, cy


def test_contains():
a = cycler('a', range(3))
b = cycler('b', range(3))

assert 'a' in a
assert 'b' in b
assert 'a' not in b
assert 'b' not in a

ab = a+b

assert 'a' in ab
assert 'b' in ab