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

Change subject: [IMPR] Use a set for lookup instead a list
......................................................................

[IMPR] Use a set for lookup instead a list

Update test accordingly

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

Approvals:
  D3r1ck01: Looks good to me, approved
  Zhuyifei1999: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/scripts/patrol.py b/scripts/patrol.py
index 8704d6d..85aa2b7 100755
--- a/scripts/patrol.py
+++ b/scripts/patrol.py
@@ -199,7 +199,7 @@

     def parse_page_tuples(self, wikitext, user=None):
         """Parse page details apart from 'user:' for use."""
-        whitelist = defaultdict(list)
+        whitelist = defaultdict(set)

         current_user = False
         parsed = mwparserfromhell.parse(wikitext)
@@ -253,7 +253,7 @@
                             verbose_output('Whitelist page: ' + page)
                         verbose_output('Adding {0}:{1}'
                                        .format(current_user, page))
-                        whitelist[current_user].append(page)
+                        whitelist[current_user].add(page)
                     else:
                         verbose_output(
                             'Discarding whitelist page for another user: '
diff --git a/tests/patrolbot_tests.py b/tests/patrolbot_tests.py
index 2185c2f..15d3217 100644
--- a/tests/patrolbot_tests.py
+++ b/tests/patrolbot_tests.py
@@ -54,30 +54,30 @@
         for gen_user in (1, 2):
             user = 'Test {0}'.format(gen_user)
             self.assertIn(user, tuples)
-            self.assertEqual(tuples[user], ['Page {0}'.format(i * gen_user)
-                                            for i in range(1, 4)])
+            self.assertEqual(tuples[user], {'Page {0}'.format(i * gen_user)
+                                            for i in range(1, 4)})
         self.assertIn('Prefixed', tuples)
-        self.assertEqual(tuples['Prefixed'], ['Page 1', 'Page 2'])
+        self.assertEqual(tuples['Prefixed'], {'Page 1', 'Page 2'})
         self.assertEqual(self.bot.parse_page_tuples('[[link]]'), {})

     def test_in_list(self):
-        """Test the method which returns whether a page is in the list."""
+        """Test the method which returns whether a page is in the set."""
         # 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'))
+        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 True if an entry starts with the title if there is no
         # exact match
-        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'))
+        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 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'))
+        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 https://gerrit.wikimedia.org/r/462482
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib3c7676052b6866ab47e1c49087fe8c73e421d4f
Gerrit-Change-Number: 462482
Gerrit-PatchSet: 7
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: Zhuyifei1999 <[email protected]>
Gerrit-Reviewer: jenkins-bot (75)
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to