jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/372794 )
Change subject: [IMPR] Enable comparing LogEntry instances ......................................................................
[IMPR] Enable comparing LogEntry instances
Bug: T173664 Change-Id: I372dfd4ff779a919d8fa4bb9bcd156221ffeee37 --- M pywikibot/logentries.py M tests/logentry_tests.py 2 files changed, 25 insertions(+), 0 deletions(-)
Approvals: Mpaa: Looks good to me, approved Dalba: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/logentries.py b/pywikibot/logentries.py index 26dd3cf..1cf135c 100644 --- a/pywikibot/logentries.py +++ b/pywikibot/logentries.py @@ -59,6 +59,19 @@ """Return the id as the hash.""" return self.logid()
+ def __eq__(self, other): + """Compare if self is equal to other.""" + if not isinstance(other, LogEntry): + pywikibot.debug("'{0}' cannot be compared with '{1}'" + .format(type(self).__name__, type(other).__name__), + _logger) + return False + return self.logid() == other.logid() and self.site == other.site + + def __ne__(self, other): + """Compare if self is not equal to other.""" + return not self == other + @property def _params(self): """ diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py index 8f9128d..cf96995 100644 --- a/tests/logentry_tests.py +++ b/tests/logentry_tests.py @@ -224,6 +224,18 @@ logentry = self._get_logentry('thanks') self.assertIsInstance(logentry.page(), pywikibot.User)
+ def test_equality(self): + """Test equality of LogEntry instances.""" + site = self.get_site('dewp') + other_site = self.get_site('tewp') + le1 = next(iter(site.logevents(reverse=True, total=1))) + le2 = next(iter(site.logevents(reverse=True, total=1))) + le3 = next(iter(other_site.logevents(reverse=True, total=1))) + self.assertEqual(le1, le2) + self.assertFalse(le1 != le2) # __ne__ test + self.assertNotEqual(le1, le3) + self.assertNotEqual(le1, site) +
class TestDeprecatedMethods(TestLogentriesBase, DeprecationTestCase):
pywikibot-commits@lists.wikimedia.org