jenkins-bot merged this change.

View Change

Approvals: Zhuyifei1999: Looks good to me, but someone else must approve Framawiki: Looks good to me, approved jenkins-bot: Verified
[simplify] return a bool value for in_list method

- return a bool value for in_list method,
finally return False instead of None
- change test_in_list accordingly which gives a bool now

detached from I4ef9009c91e485509e

Change-Id: Ifdf45db1117ebdd8358727ded08c5e537fb27bc2
---
M scripts/patrol.py
M tests/patrolbot_tests.py
2 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/scripts/patrol.py b/scripts/patrol.py
index e72e7ad..f68902f 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -172,12 +172,12 @@

# quick check for exact match
if title in pagelist:
- return title
+ return True

# quick check for wildcard
if '' in pagelist:
verbose_output('wildcarded')
- return '.*'
+ return True

for item in pagelist:
verbose_output('checking against whitelist item = ' + item)
@@ -185,12 +185,12 @@
if isinstance(item, LinkedPagesRule):
verbose_output('invoking programmed rule')
if item.match(title):
- return item
+ return True

elif title_match(item, title):
- return item
-
+ return True
verbose_output('not found')
+ return False

def parse_page_tuples(self, wikitext, user=None):
"""Parse page details apart from 'user:' for use."""
diff --git a/tests/patrolbot_tests.py b/tests/patrolbot_tests.py
index 17be8a1..1920c00 100644
--- a/tests/patrolbot_tests.py
+++ b/tests/patrolbot_tests.py
@@ -56,23 +56,22 @@

def test_in_list(self):
"""Test the method which returns whether a page is in the list."""
- # Return the title if there is an exact match
- self.assertEqual(self.bot.in_list(['Foo', 'Foobar'], 'Foo'), 'Foo')
- self.assertEqual(self.bot.in_list(['Foo', 'Foobar'], 'Foobar'),
- 'Foobar')
+ # Return True if there is an exact match
+ self.assertTrue(self.bot.in_list(['Foo', 'Foobar'], 'Foo'))
+ self.assertTrue(self.bot.in_list(['Foo', 'Foobar'], 'Foobar'))
+ self.assertFalse(self.bot.in_list(['Foo', 'Foobar'], 'Bar'))

- # Return the first entry which starts with the title if there is no
+ # Return True if an entry starts with the title if there is no
# exact match
- self.assertEqual(self.bot.in_list(['Foo', 'Foobar'], 'Foob'), 'Foo')
- self.assertEqual(self.bot.in_list(['Foo', 'Foobar'], 'Foobarz'),
- 'Foo')
- self.assertEqual(self.bot.in_list(['Foo', 'Foobar', 'Bar'], 'Barz'),
- 'Bar')
+ self.assertTrue(self.bot.in_list(['Foo', 'Foobar'], 'Foob'))
+ self.assertTrue(self.bot.in_list(['Foo', 'Foobar'], 'Foobarz'))
+ self.assertTrue(self.bot.in_list(['Foo', 'Foobar', 'Bar'], 'Barz'))
+ self.assertFalse(self.bot.in_list(['Foobar', 'Bar'], 'Foo'))

- # '' returns .* if there is no exact match
- self.assertEqual(self.bot.in_list([''], 'Foo'), '.*')
- self.assertEqual(self.bot.in_list(['', 'Foobar'], 'Foo'), '.*')
- self.assertEqual(self.bot.in_list(['', 'Foo'], 'Foo'), 'Foo')
+ # '' returns True if there is no exact match
+ self.assertTrue(self.bot.in_list([''], 'Foo'))
+ self.assertTrue(self.bot.in_list(['', 'Foobar'], 'Foo'))
+ self.assertTrue(self.bot.in_list(['', 'Foo'], 'Foo'))


if __name__ == '__main__': # pragma: no cover

To view, visit change 467932. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifdf45db1117ebdd8358727ded08c5e537fb27bc2
Gerrit-Change-Number: 467932
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Framawiki <framawiki@tools.wmflabs.org>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)