jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/370213 )

Change subject: [bugfix] Filter bool, None and int types in the right way
......................................................................


[bugfix] Filter bool, None and int types in the right way

- some tests added

Bug: T172521
Change-Id: I9e47935272ca9d05b45de05dfbfe64a83ce54131
---
M pywikibot/comms/eventstreams.py
M tests/eventstreams_tests.py
2 files changed, 17 insertions(+), 2 deletions(-)

Approvals:
  Merlijn van Deen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py
index 2236481..240e260 100644
--- a/pywikibot/comms/eventstreams.py
+++ b/pywikibot/comms/eventstreams.py
@@ -171,11 +171,11 @@
         # 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
diff --git a/tests/eventstreams_tests.py b/tests/eventstreams_tests.py
index 8e440bc..4f4cdc3 100644
--- a/tests/eventstreams_tests.py
+++ b/tests/eventstreams_tests.py
@@ -179,6 +179,21 @@
         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': []}

-- 
To view, visit https://gerrit.wikimedia.org/r/370213
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9e47935272ca9d05b45de05dfbfe64a83ce54131
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <i...@gno.de>
Gerrit-Reviewer: John Vandenberg <jay...@gmail.com>
Gerrit-Reviewer: Magul <tomasz.magul...@gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhall...@arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.w...@gmail.com>
Gerrit-Reviewer: Multichill <maar...@mdammers.nl>
Gerrit-Reviewer: Ottomata <ao...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to