jenkins-bot merged this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] Fix the comparison in archivebot

Fix the comparison in archivebot.

Also removed cause of deprecation for 'test_family'
in TestDiscussionPageObject.

Bug: T228587
Change-Id: Id3f3324db0856603a4539e017fcef44d0bedc977
---
M scripts/archivebot.py
M tests/archivebot_tests.py
2 files changed, 70 insertions(+), 4 deletions(-)

diff --git a/scripts/archivebot.py b/scripts/archivebot.py
index c0381f8..86b54a3 100755
--- a/scripts/archivebot.py
+++ b/scripts/archivebot.py
@@ -571,9 +571,14 @@
"""Load and validate archiver template."""
pywikibot.output('Looking for: {{%s}} in %s' % (self.tpl.title(),
self.page))
- for tpl in self.page.raw_extracted_templates:
- if tpl[0] == self.tpl.title(with_ns=False):
- for item, value in tpl[1].items():
+ for tpl, params in self.page.raw_extracted_templates:
+ try: # Check tpl name before comparing; it might be invalid.
+ tpl_page = pywikibot.Page(self.site, tpl, ns=10)
+ tpl_page.title()
+ except pywikibot.Error:
+ continue
+ if tpl_page == self.tpl:
+ for item, value in params.items():
self.set_attr(item.strip(), value.strip())
break
else:
diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py
index 6896711..c8b5bc3 100644
--- a/tests/archivebot_tests.py
+++ b/tests/archivebot_tests.py
@@ -240,7 +240,7 @@
"""Test DiscussionPage object."""

cached = True
- family = 'test'
+ family = 'wikipedia'
code = 'test'

def testTwoThreadsWithCommentedOutThread(self):
@@ -301,6 +301,67 @@
self.assertEqual([x.title for x in page.threads], ['A', 'B'])


+class TestPageArchiverObject(TestCase):
+
+ """Test PageArchiver object."""
+
+ cached = True
+ family = 'wikipedia'
+ code = 'test'
+
+ def testLoadConfigInTemplateNamespace(self):
+ """Test loading of config with TEMPLATE_PAGE in Template ns.
+
+ Talk:For-pywikibot-archivebot-01 must have:
+
+ {{Pywikibot_archivebot
+ |archive = Talk:Main_Page/archive
+ |algo = old(30d)
+ }}
+ """
+ site = self.get_site()
+ page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot-01')
+
+ # TEMPLATE_PAGE assumed in ns=10 if ns is not explicit.
+ tmpl_with_ns = pywikibot.Page(site, 'Template:Pywikibot_archivebot')
+ tmpl_without_ns = pywikibot.Page(site, 'Pywikibot_archivebot', ns=10)
+
+ try:
+ archivebot.PageArchiver(page, tmpl_with_ns, '')
+ except pywikibot.Error as e:
+ self.fail('PageArchiver() raised {}!'.format(e))
+
+ try:
+ archivebot.PageArchiver(page, tmpl_without_ns, '')
+ except pywikibot.Error as e:
+ self.fail('PageArchiver() raised {}!'.format(e))
+
+ def testLoadConfigInOtherNamespace(self):
+ """Test loading of config with TEMPLATE_PAGE not in Template ns.
+
+ Talk:For-pywikibot-archivebot must have:
+
+ {{User:MiszaBot/config
+ |archive = Talk:Main_Page/archive
+ |algo = old(30d)
+ }}
+ """
+ site = self.get_site()
+ page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot')
+
+ tmpl_with_ns = pywikibot.Page(site, 'User:MiszaBot/config', ns=10)
+ tmpl_without_ns = pywikibot.Page(site, 'MiszaBot/config', ns=10)
+
+ # TEMPLATE_PAGE assumed in ns=10 if ns is not explicit.
+ try:
+ archivebot.PageArchiver(page, tmpl_with_ns, '')
+ except pywikibot.Error as e:
+ self.fail('PageArchiver() raised {}!'.format(e))
+
+ with self.assertRaises(archivebot.MissingConfigError):
+ archivebot.PageArchiver(page, tmpl_without_ns, '')
+
+
if __name__ == '__main__': # pragma: no cover
try:
unittest.main()

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id3f3324db0856603a4539e017fcef44d0bedc977
Gerrit-Change-Number: 528474
Gerrit-PatchSet: 9
Gerrit-Owner: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Dalba <dalba.wiki@gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: John Vandenberg <jayvdb@gmail.com>
Gerrit-Reviewer: Mpaa <mpaa.wiki@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999@gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
Gerrit-CC: MarcoAurelio <maurelio@tools.wmflabs.org>