jenkins-bot has submitted this change and it was merged.
Change subject: Improve fixArabicLetters, add tests ......................................................................
Improve fixArabicLetters, add tests
- Fixed bugs related to python3. - Corrected use of replaceExcept. - Added two tests, one for German Wikipedia, one for Persian Wikipedia.
Signed-off-by: xqt info@gno.de
Change-Id: I421a1f9d2a7ff89584b7b8403b29245402f6cf86 --- M pywikibot/cosmetic_changes.py M tests/cosmetic_changes_tests.py 2 files changed, 25 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index 7fedee0..bf16474 100755 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -50,7 +50,7 @@ """ # # (C) xqt, 2009-2015 -# (C) Pywikibot team, 2006-2015 +# (C) Pywikibot team, 2006-2016 # # Distributed under the terms of the MIT license. # @@ -854,7 +854,7 @@
def fixArabicLetters(self, text): if self.site.code not in ['ckb', 'fa']: - return + return text exceptions = [ 'gallery', 'file', @@ -880,11 +880,11 @@ faChrs = u'ءاآأإئؤبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیةيك' + digits['fa'] new = digits.pop(self.site.code) # This only works if there are only two items in digits dict - old = digits[digits.keys()[0]] + old = digits[list(digits.keys())[0]] # not to let bot edits in latin content exceptions.append(re.compile(u"[^%(fa)s] *?"*? *?, *?[^%(fa)s]" % {'fa': faChrs})) - text = textlib.replaceExcept(text, u',', u'،', exceptions) + text = textlib.replaceExcept(text, ',', '،', exceptions, site=self.site) if self.site.code == 'ckb': text = textlib.replaceExcept(text, '\u0647([.\u060c_<\]\s])', diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py index cf8b7ae..80a0595 100644 --- a/tests/cosmetic_changes_tests.py +++ b/tests/cosmetic_changes_tests.py @@ -214,6 +214,12 @@ self.assertEqual('42 °C', self.cct.fixTypo('42 ºC'))
+ def test_fixArabicLetters(self): + """Test fixArabicLetters.""" + text = '1234,كىي' + # fixArabicLetters must not change text when site is not fa or ckb + self.assertEqual(text, self.cct.fixArabicLetters(text)) +
class TestLiveCosmeticChanges(TestCosmeticChanges):
@@ -287,6 +293,21 @@ self.cct.replaceDeprecatedTemplates('{{Quelle|Test}}'))
+class TestCosmeticChangesPersian(TestCosmeticChanges): + + """Test cosmetic changes methods in Persian Wikipedia.""" + + family = 'wikipedia' + code = 'fa' + + def test_fixArabicLetters(self): + """Test fixArabicLetters.""" + self.assertEqual(self.cct.fixArabicLetters('A,b,ا,۴,'), + 'A,b،ا،۴،') + self.assertEqual(self.cct.fixArabicLetters('كي'), + 'کی') + # Once numbering fixes are enabled we can add tests. + if __name__ == '__main__': try: unittest.main()
pywikibot-commits@lists.wikimedia.org