jenkins-bot has submitted this change and it was merged.
Change subject: Fix ComparableMixin
......................................................................
Fix ComparableMixin
The implementation in 6c6b185e failed for inequality,
resulting in 'Namespace 0 < int 0' returning True.
Change-Id: Ia00ab2dd68938b0520253f7017d685aa03c36592
(cherry picked from commit 57a55ff9929f7c692a041ed209a913422f097fe5)
---
M pywikibot/tools/__init__.py
M tests/namespace_tests.py
2 files changed, 25 insertions(+), 13 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 00c7fc2..bb88166 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -115,27 +115,27 @@
"""Mixin class to allow comparing to other objects which are
comparable."""
def __lt__(self, other):
- """Compare if other is less than self."""
- return other >= self._cmpkey()
-
- def __le__(self, other):
- """Compare if other is less equals self."""
+ """Compare if self is less than other."""
return other > self._cmpkey()
+ def __le__(self, other):
+ """Compare if self is less equals other."""
+ return other >= self._cmpkey()
+
def __eq__(self, other):
- """Compare if other is equal to self."""
+ """Compare if self is equal to other."""
return other == self._cmpkey()
def __ge__(self, other):
- """Compare if other is greater equals self."""
- return other < self._cmpkey()
-
- def __gt__(self, other):
- """Compare if other is greater than self."""
+ """Compare if self is greater equals other."""
return other <= self._cmpkey()
+ def __gt__(self, other):
+ """Compare if self is greater than other."""
+ return other < self._cmpkey()
+
def __ne__(self, other):
- """Compare if other is not equal to self."""
+ """Compare if self is not equal to other."""
return other != self._cmpkey()
diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py
index 6f18a73..ca1790a 100644
--- a/tests/namespace_tests.py
+++ b/tests/namespace_tests.py
@@ -145,13 +145,17 @@
self.assertEqual(a, 0)
self.assertEqual(a, '')
+ self.assertFalse(a < 0)
+ self.assertFalse(a > 0)
self.assertNotEqual(a, None)
+
+ self.assertGreater(a, -1)
x = Namespace(id=6, custom_name=u'dummy',
canonical_name=u'File',
aliases=[u'Image', u'Immagine'])
y = Namespace(id=6, custom_name=u'ملف', canonical_name=u'File',
aliases=[u'Image', u'Immagine'])
- z = Namespace(id=7, custom_name=u'dummy',
canonical_name=u'File',
+ z = Namespace(id=7, custom_name=u'dummy 7',
canonical_name=u'File',
aliases=[u'Image', u'Immagine'])
self.assertEqual(x, x)
@@ -170,11 +174,19 @@
self.assertEqual(x, u'image')
self.assertEqual(x, u'Image')
+ self.assertFalse(x < 6)
+ self.assertFalse(x > 6)
+
self.assertEqual(y, u'ملف')
self.assertLess(a, x)
+ self.assertLess(x, z)
+ self.assertLessEqual(a, x)
self.assertGreater(x, a)
+ self.assertGreater(x, 0)
self.assertGreater(z, x)
+ self.assertGreaterEqual(x, a)
+ self.assertGreaterEqual(y, x)
self.assertIn(6, [x, y, z])
self.assertNotIn(8, [x, y, z])
--
To view, visit
https://gerrit.wikimedia.org/r/243104
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia00ab2dd68938b0520253f7017d685aa03c36592
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>