XZise has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232010
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, 17 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/10/232010/1
diff --git a/scripts/replace.py b/scripts/replace.py
index ec8d114..837b8e0 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -903,7 +903,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 e750b98..9a1f68f 100644
--- a/tests/data/fixes.py
+++ b/tests/data/fixes.py
@@ -59,3 +59,10 @@
('5', '6'),
]
}
+
+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 8898834..43e6047 100644
--- a/tests/replacebot_tests.py
+++ b/tests/replacebot_tests.py
@@ -109,7 +109,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."""
@@ -200,6 +201,12 @@
self._test_replacement(bot.replacements[0])
self._test_fix_replacement(bot.replacements[1])
+ 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: newchange
Gerrit-Change-Id: I1d64ba6d456a08a3da5662b66002ab5c417b61ce
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits