jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/434107 )
Change subject: [bugfix][TEST] Exclude links from disabled areas in fixing_redirects.py ......................................................................
[bugfix][TEST] Exclude links from disabled areas in fixing_redirects.py
Bug: T166506 Change-Id: Ibf1723730e9b77bd3b75c5e7ca3ddafeb1ccef15 --- A docs/api_ref/tests/fixing_redirects_tests.rst M docs/api_ref/tests/index.rst M scripts/fixing_redirects.py A tests/fixing_redirects_tests.py 4 files changed, 50 insertions(+), 5 deletions(-)
Approvals: Framawiki: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/docs/api_ref/tests/fixing_redirects_tests.rst b/docs/api_ref/tests/fixing_redirects_tests.rst new file mode 100644 index 0000000..78a3cc9 --- /dev/null +++ b/docs/api_ref/tests/fixing_redirects_tests.rst @@ -0,0 +1,7 @@ +tests.fixing_redirects_tests module +===================================== + +.. automodule:: tests.fixing_redirects_tests + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api_ref/tests/index.rst b/docs/api_ref/tests/index.rst index 1d77680..ea77f14 100644 --- a/docs/api_ref/tests/index.rst +++ b/docs/api_ref/tests/index.rst @@ -97,6 +97,7 @@ data_ingestion<./data_ingestion_tests> deletionbot<./deletionbot_tests> disambredir<./disambredir_tests> + fixing_redirects<./fixing_redirects_tests> generate_family_files<./generate_family_files_tests> generate_user_files<./generate_user_files_tests> imagecopy<./imagecopy_tests> diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py index b12ffd0..062571c 100755 --- a/scripts/fixing_redirects.py +++ b/scripts/fixing_redirects.py @@ -13,7 +13,7 @@
""" # -# (C) Pywikibot team, 2004-2017 +# (C) Pywikibot team, 2004-2018 # # Distributed under the terms of the MIT license. # @@ -25,7 +25,7 @@ from pywikibot import pagegenerators from pywikibot.bot import (SingleSiteBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot, suggest_help) -from pywikibot.textlib import does_text_contain_section +from pywikibot.textlib import does_text_contain_section, isDisabled from pywikibot.tools.formatter import color_format from pywikibot.tools import first_lower, first_upper as firstcap
@@ -64,9 +64,11 @@ break # Make sure that next time around we will not find this same hit. curpos = m.start() + 1 - # ignore interwiki links and links to sections of the same page - if m.group('title').strip() == '' or \ - mysite.isInterwikiLink(m.group('title')): + # ignore interwiki links, links in the disabled area + # and links to sections of the same page + if (m.group('title').strip() == '' + or mysite.isInterwikiLink(m.group('title')) + or isDisabled(text, m.start())): continue else: actualLinkPage = pywikibot.Page(targetPage.site, m.group('title')) diff --git a/tests/fixing_redirects_tests.py b/tests/fixing_redirects_tests.py new file mode 100644 index 0000000..86c985f --- /dev/null +++ b/tests/fixing_redirects_tests.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +"""Test fixing redirects bot module.""" +# +# (C) Pywikibot team, 2018 +# +# Distributed under the terms of the MIT license. +# +from __future__ import absolute_import, unicode_literals + +import pywikibot + +from scripts.fixing_redirects import FixingRedirectBot + +from tests.aspects import TestCase, unittest + + +class TestFixingRedirects(TestCase): + """Test fixing redirects.""" + + family = 'wikipedia' + code = 'en' + + def test_disabled(self): + """Test disabled parts of fixing redirects.""" + bot = FixingRedirectBot() + text = ('<!--[[Template:Doc]]--><source>[[Template:Doc]]</source>' + '[[:cs:Template:Dokumentace]][[#Documentation]]') + linked = pywikibot.Page(self.site, 'Template:Doc') + target = pywikibot.Page(self.site, 'Template:Documentation') + new_text = bot.replace_links(text, linked, target) + self.assertEqual(text, new_text) + + +if __name__ == '__main__': # pragma: no cover + unittest.main()
pywikibot-commits@lists.wikimedia.org