XZise has uploaded a new change for review. https://gerrit.wikimedia.org/r/241565
Change subject: [FIX] Removing disabled parts without mwpfh ...................................................................... [FIX] Removing disabled parts without mwpfh When `mwparserfromhell` is not installed it won't remove disabled parts unless that parameter is explicitly set to `True`. Before 13cd73de it was always set to `True` when using the regex variant but after that patch it only changed the default value of `None` when `mwparserfromhell` is used. Change-Id: I255823fc574c9d03f8d9961350a3545f3bcea3fb --- M pywikibot/textlib.py M tests/textlib_tests.py 2 files changed, 49 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/65/241565/1 diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index 5998ac0..36c6e81 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -1291,9 +1291,8 @@ use_mwparserfromhell = (config.use_mwparserfromhell and not isinstance(mwparserfromhell, Exception)) - if use_mwparserfromhell: - if remove_disabled_parts is None: - remove_disabled_parts = False + if remove_disabled_parts is None: + remove_disabled_parts = not use_mwparserfromhell if remove_disabled_parts: text = removeDisabledParts(text) diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index e50d5ef..d736970 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -23,6 +23,7 @@ from tests.aspects import ( unittest, require_modules, TestCase, DefaultDrySiteTestCase, + PatchingTestCase, ) files = {} @@ -557,6 +558,52 @@ self.assertTrue(m.group(0).endswith('foo {{bar}}')) +class TestGenericTemplateParams(PatchingTestCase): + + """Test whether the generic function forwards the call correctly.""" + + net = False + + @PatchingTestCase.patched(textlib, 'extract_templates_and_params_mwpfh') + def extract_mwpfh(self, text, *args, **kwargs): + """Patched call to extract_templates_and_params_mwpfh.""" + self._text = text + self._mwpfh = True + + @PatchingTestCase.patched(textlib, 'extract_templates_and_params_regex') + def extract_regex(self, text, *args, **kwargs): + """Patched call to extract_templates_and_params_regex.""" + self._text = text + self._mwpfh = False + + def test_removing_disabled_parts_regex(self): + """Test removing disabled parts when using the regex variant.""" + self.patch(config, 'use_mwparserfromhell', False) + textlib.extract_templates_and_params('{{a<!-- -->}}', True) + self.assertEqual(self._text, '{{a}}') + self.assertFalse(self._mwpfh) + textlib.extract_templates_and_params('{{a<!-- -->}}', False) + self.assertEqual(self._text, '{{a<!-- -->}}') + self.assertFalse(self._mwpfh) + textlib.extract_templates_and_params('{{a<!-- -->}}') + self.assertEqual(self._text, '{{a}}') + self.assertFalse(self._mwpfh) + + @require_modules('mwparserfromhell') + def test_removing_disabled_parts_mwpfh(self): + """Test removing disabled parts when using the mwpfh variant.""" + self.patch(config, 'use_mwparserfromhell', True) + textlib.extract_templates_and_params('{{a<!-- -->}}', True) + self.assertEqual(self._text, '{{a}}') + self.assertTrue(self._mwpfh) + textlib.extract_templates_and_params('{{a<!-- -->}}', False) + self.assertEqual(self._text, '{{a<!-- -->}}') + self.assertTrue(self._mwpfh) + textlib.extract_templates_and_params('{{a<!-- -->}}') + self.assertEqual(self._text, '{{a<!-- -->}}') + self.assertTrue(self._mwpfh) + + class TestReplaceLinks(TestCase): """Test the replace_links function in textlib.""" -- To view, visit https://gerrit.wikimedia.org/r/241565 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I255823fc574c9d03f8d9961350a3545f3bcea3fb Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: XZise <commodorefabia...@gmx.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits