jenkins-bot has submitted this change and it was merged.

Change subject: [FIX] replace: Support callable as replacement
......................................................................


[FIX] replace: Support callable as replacement

Before 7a98d58f the replace script supports callables as a replacement when
using a fix. But that patch it expected an iterable. This disables the check
for invisible characters when the replacement is a callable.

Change-Id: I1d64ba6d456a08a3da5662b66002ab5c417b61ce
---
M scripts/replace.py
M tests/data/fixes.py
M tests/replacebot_tests.py
3 files changed, 18 insertions(+), 2 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/replace.py b/scripts/replace.py
index 529c4da..6c5e97c 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -979,7 +979,8 @@
                 pywikibot.warning('The old string "{0}" contains formatting '
                                   'characters like U+200E'.format(
                     chars.replace_invisible(replacement[0])))
-            if chars.contains_invisible(replacement[1]):
+            if (not callable(replacement[1]) and
+                    chars.contains_invisible(replacement[1])):
                 pywikibot.warning('The new string "{0}" contains formatting '
                                   'characters like U+200E'.format(
                     chars.replace_invisible(replacement[1])))
diff --git a/tests/data/fixes.py b/tests/data/fixes.py
index 5c2fd0e..fcdf8c1 100644
--- a/tests/data/fixes.py
+++ b/tests/data/fixes.py
@@ -70,3 +70,10 @@
         ('1', '2'),
     ]
 }
+
+fixes['no-msg-callable'] = {
+    'regex': False,
+    'replacements': [
+        ('1', lambda match: str(match.start())),
+    ]
+}
diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py
index cf3858f..03aee98 100644
--- a/tests/replacebot_tests.py
+++ b/tests/replacebot_tests.py
@@ -110,7 +110,8 @@
         """Test a replacement from the command line."""
         self.assertIsInstance(replacement, clazz)
         self.assertEqual(replacement.old, str(offset * 2 + 1))
-        self.assertEqual(replacement.new, str(offset * 2 + 2))
+        if not callable(replacement.new):
+            self.assertEqual(replacement.new, str(offset * 2 + 2))
 
     def _test_fix_replacement(self, replacement, length=1, offset=0, 
msg=False):
         """Test a replacement from a fix."""
@@ -230,6 +231,13 @@
         self._apply(bot, 'Hello 2', title='Allowed')
         self._apply(bot, 'Hello 1', missing=True, title='Allowed Declined')
 
+    def test_fix_callable(self):
+        """Test fix replacements using a callable."""
+        bot = self._get_bot(True, '-fix:no-msg-callable')
+        self.assertEqual(len(bot.replacements), 1)
+        self._test_fix_replacement(bot.replacements[0])
+        self.assertTrue(callable(bot.replacements[0].new))
+
 
 if __name__ == '__main__':
     try:

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1d64ba6d456a08a3da5662b66002ab5c417b61ce
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to