Ladsgroup has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/249114

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.

Change-Id: I421a1f9d2a7ff89584b7b8403b29245402f6cf86
---
M pywikibot/cosmetic_changes.py
M tests/cosmetic_changes_tests.py
2 files changed, 24 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/14/249114/1

diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index 8aabc09..0bf3838 100755
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -830,7 +830,7 @@
 
     def fixArabicLetters(self, text):
         if self.site.code not in ['ckb', 'fa']:
-            return
+            return text
         exceptions = [
             'gallery',
             'hyperlink',
@@ -855,7 +855,7 @@
         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]]
         # do not change inside file links
         namespaces = list(self.site.namespace(6, all=True))
         pattern = re.compile(
@@ -866,7 +866,7 @@
         exceptions.append(re.compile(u"[^%(fa)s] *?\"*? *?, *?[^%(fa)s]"
                                      % {'fa': faChrs}))
         exceptions.append(pattern)
-        text = textlib.replaceExcept(text, u',', u'،', exceptions)
+        text = textlib.replaceExcept(text, u',', u'،', 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 17e270d..bc94fbe 100644
--- a/tests/cosmetic_changes_tests.py
+++ b/tests/cosmetic_changes_tests.py
@@ -194,6 +194,12 @@
         self.assertEqual('42&nbsp;°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):
 
@@ -267,6 +273,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(u'A,b,ا,۴,'),
+                         'A,b،ا،۴،')
+        self.assertEqual(self.cct.fixArabicLetters('كي'),
+                         'کی')
+        # Once numbering fixes are enabled we can add tests.
+
 if __name__ == '__main__':
     try:
         unittest.main()

-- 
To view, visit https://gerrit.wikimedia.org/r/249114
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I421a1f9d2a7ff89584b7b8403b29245402f6cf86
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to