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 --- M pywikibot/tools/__init__.py M tests/namespace_tests.py 2 files changed, 25 insertions(+), 13 deletions(-)
Approvals: XZise: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index aced6c0..03fe23d 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -137,27 +137,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 f2e2373..024ba7f 100644 --- a/tests/namespace_tests.py +++ b/tests/namespace_tests.py @@ -132,13 +132,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) @@ -157,11 +161,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])
pywikibot-commits@lists.wikimedia.org