jenkins-bot has submitted this change and it was merged.
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.
Bug: T113892
Change-Id: I255823fc574c9d03f8d9961350a3545f3bcea3fb
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 51 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
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..0b0205e 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 = {}
@@ -415,7 +416,8 @@
def test_extract_templates_params(self):
"""Test that the normal entry point works."""
self._common_results(
- textlib.extract_templates_and_params)
+ functools.partial(textlib.extract_templates_and_params,
+ remove_disabled_parts=False))
def test_template_simple_regex(self):
"""Test using simple regex."""
@@ -557,6 +559,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: merged
Gerrit-Change-Id: I255823fc574c9d03f8d9961350a3545f3bcea3fb
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 <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits