jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/324476 )
Change subject: Ignore first letter case on 'first-letter' sites, obey it otherwise ......................................................................
Ignore first letter case on 'first-letter' sites, obey it otherwise
This also unbreaks broken tests.
Bug: T130917 Change-Id: Icb1220b47bd844667ce222fc4539a5724c76cfce --- M pywikibot/cosmetic_changes.py M tests/cosmetic_changes_tests.py 2 files changed, 19 insertions(+), 15 deletions(-)
Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index 6f4bfac..2d3da9c 100755 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -514,16 +514,24 @@ if trailingChars: label += trailingChars
- if titleWithSection == label or \ - first_lower(titleWithSection) == label: - newLink = "[[%s]]" % label - # Check if we can create a link with trailing characters - # instead of a pipelink - elif (len(titleWithSection) <= len(label) and - label[:len(titleWithSection)] == titleWithSection and - trailR.sub('', label[len(titleWithSection):]) == ''): - newLink = "[[%s]]%s" % (label[:len(titleWithSection)], - label[len(titleWithSection):]) + if self.site.siteinfo['case'] == 'first-letter': + firstcase_title = first_lower(titleWithSection) + firstcase_label = first_lower(label) + else: + firstcase_title = titleWithSection + firstcase_label = label + + if firstcase_label.startswith(firstcase_title): + if firstcase_label == firstcase_title: + newLink = '[[%s]]' % label + # Check if we can create a link with trailing characters + # instead of a pipelink + elif trailR.sub('', + label[len(titleWithSection):]) == '': + newLink = '[[%s]]%s' % ( + label[:len(titleWithSection)], + label[len(titleWithSection):]) + else: # Try to capitalize the first letter of the title. # Not useful for languages that don't capitalize nouns. diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py index fb9b407..b5ef83e 100644 --- a/tests/cosmetic_changes_tests.py +++ b/tests/cosmetic_changes_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Test cosmetic_changes module.""" # -# (C) Pywikibot team, 2015-2016 +# (C) Pywikibot team, 2015-2017 # # Distributed under the terms of the MIT license. # @@ -257,10 +257,6 @@ self.cct.cleanUpLinks('[[sand|sand]]box')) self.assertEqual('[[Sand|demospace]]', self.cct.cleanUpLinks('[[sand|demo]]space')) - - @unittest.expectedFailure - def test_cleanUpLinks_pipes_fail(self): - """Test cleanUpLinks method.""" self.assertEqual('[[Title]]', self.cct.cleanUpLinks('[[title|Title]]')) self.assertEqual('[[Sand]]box',