Skip to content

Commit

Permalink
Merge "[bugfix] Filter bool, None and int types in the right way"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Aug 6, 2017
2 parents 267eefe + a753d77 commit bc073c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pywikibot/comms/eventstreams.py
Expand Up @@ -171,11 +171,11 @@ def foo(data):
# register pairs of keys and items as a filter function
for key, value in kwargs.items():
# append function for singletons
if value in (True, False, None):
if isinstance(value, (bool, type(None))):
self.filter[ftype].append(lambda e: key in e and
e[key] is value)
# append function for a single value
elif isinstance(value, StringTypes):
elif isinstance(value, (StringTypes, int)):
self.filter[ftype].append(lambda e: key in e and
e[key] == value)
# append function for an iterable as value
Expand Down
15 changes: 15 additions & 0 deletions tests/eventstreams_tests.py
Expand Up @@ -179,6 +179,21 @@ def test_filter_function_none(self):
self.es.register_filter(lambda x: True, ftype='none')
self.assertFalse(self.es.streamfilter(self.data))

def test_filter_false(self):
"""Test EventStreams filter with assignment of True."""
self.es.register_filter(foo=False)
self.assertFalse(self.es.streamfilter(self.data))

def test_filter_true(self):
"""Test EventStreams filter with assignment of False."""
self.es.register_filter(foo=True)
self.assertTrue(self.es.streamfilter(self.data))

def test_filter_value(self):
"""Test EventStreams filter with assignment of a int value."""
self.es.register_filter(foo=10)
self.assertFalse(self.es.streamfilter(self.data))

def _test_filter(self, none_type, all_type, any_type, result):
"""Test a single fixed filter."""
self.es.filter = {'all': [], 'any': [], 'none': []}
Expand Down

0 comments on commit bc073c1

Please sign in to comment.