jenkins-bot has submitted this change and it was merged.
Change subject: [FEAT] Test that replace applies title exceptions
......................................................................
[FEAT] Test that replace applies title exceptions
This adds a test to verify that the title exceptions specified by a fix are
applied correctly with revision 20b289d3.
Change-Id: Idde108ae9667707fffa0ceb20383cc6179b40470
---
M tests/data/fixes.py
M tests/replacebot_tests.py
2 files changed, 49 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/data/fixes.py b/tests/data/fixes.py
index e750b98..5c2fd0e 100644
--- a/tests/data/fixes.py
+++ b/tests/data/fixes.py
@@ -59,3 +59,14 @@
('5', '6'),
]
}
+
+fixes['no-msg-title-exceptions'] = {
+ 'regex': False,
+ 'exceptions': {
+ 'title': ['Declined'],
+ 'require-title': ['Allowed'],
+ },
+ 'replacements': [
+ ('1', '2'),
+ ]
+}
diff --git a/tests/replacebot_tests.py b/tests/replacebot_tests.py
index 8898834..cf3858f 100644
--- a/tests/replacebot_tests.py
+++ b/tests/replacebot_tests.py
@@ -11,6 +11,8 @@
#
import os
+import pywikibot
+
from pywikibot import fixes
from scripts import replace
@@ -37,23 +39,22 @@
def setUp(self):
"""Replace the original bot class with a fake one."""
- class FakeReplaceBot(object):
+ class FakeReplaceBot(replace.ReplaceRobot):
"""A fake bot class for the minimal support."""
changed_pages = -42 # show that weird number to show this was used
- def __init__(inner_self, generator, replacements, exceptions={},
- always=False, allowoverlap=False, recursive=False,
- addedCat=None, sleep=None, summary='', site=None,
- **kwargs):
- inner_self.replacements = replacements
- inner_self.site = site
+ def __init__(inner_self, *args, **kwargs):
+ # Unpatch already here, as otherwise super calls will use
+ # this class' super which is the class itself
+ replace.ReplaceRobot = self._original_bot
+ super(FakeReplaceBot, inner_self).__init__(*args, **kwargs)
self.bots.append(inner_self)
def run(inner_self):
"""Nothing to do here."""
- pass
+ inner_self.changed_pages = -47 # show that run was called
def patched_login(sysop=False):
"""Do nothing."""
@@ -122,6 +123,7 @@
else:
self.assertIs(replacement.edit_summary,
replacement.fix_set.edit_summary)
+ self.assertIs(replacement.fix_set, replacement.container)
self.assertIsInstance(replacement.fix_set, replace.ReplacementList)
self.assertIsInstance(replacement.fix_set, list)
self.assertIn(replacement, replacement.fix_set)
@@ -140,7 +142,24 @@
else:
self.assertNotIn(self.SUMMARY_CONFIRMATION, self.inputs)
self.assertEqual(bot.site, self.site)
+ self.assertEqual(bot.changed_pages, -47)
return bot
+
+ def _apply(self, bot, expected, missing=None, title='Test page'):
+ """Test applying a test change."""
+ applied = set()
+ if missing is True:
+ required_applied = set()
+ else:
+ required_applied = set(bot.replacements)
+ if missing:
+ required_applied -= set(missing)
+ # shouldn't be edited anyway
+ page = pywikibot.Page(self.site, title)
+ self.assertEqual(expected,
+ bot.apply_replacements('Hello 1', applied, page))
+ self.assertEqual(applied, required_applied)
+ self.assertEqual(expected, bot.doReplacements('Hello 1', page))
def test_only_cmd(self):
"""Test command line replacements only."""
@@ -200,6 +219,17 @@
self._test_replacement(bot.replacements[0])
self._test_fix_replacement(bot.replacements[1])
+ def test_except_title(self):
+ """Test excepting and requiring a title specific to fix."""
+ bot = self._get_bot(True, '-fix:no-msg-title-exceptions')
+ self.assertEqual(len(bot.replacements), 1)
+ self._test_fix_replacement(bot.replacements[0])
+ self.assertIn('title', bot.replacements[0].exceptions)
+ self.assertIn('require-title', bot.replacements[0].exceptions)
+ self._apply(bot, 'Hello 1', missing=True, title='Neither')
+ self._apply(bot, 'Hello 2', title='Allowed')
+ self._apply(bot, 'Hello 1', missing=True, title='Allowed Declined')
+
if __name__ == '__main__':
try:
--
To view, visit https://gerrit.wikimedia.org/r/232016
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idde108ae9667707fffa0ceb20383cc6179b40470
Gerrit-PatchSet: 3
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: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits