jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1351401?usp=email )
Change subject: replicate_wiki: Isolate replacements per destination
......................................................................
replicate_wiki: Isolate replacements per destination
Keep the original page text separate from each destination's working
copy so replacements for one wiki cannot affect later destinations.
Add a regression test covering different replacement rules and a
destination without replacements.
Change-Id: Ia2041cf8b815d8a0599de4349f3106c0bdcd8d6e
---
M scripts/replicate_wiki.py
M tests/__init__.py
A tests/replicate_wiki_tests.py
3 files changed, 60 insertions(+), 1 deletion(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py
index a026259..5299bbc 100755
--- a/scripts/replicate_wiki.py
+++ b/scripts/replicate_wiki.py
@@ -188,7 +188,7 @@
"""Check one page."""
pywikibot.info('\nChecking ' + pagename)
page1 = Page(self.original, pagename)
- txt1 = page1.text
+ source_text = page1.text
if self.options.dest_namespace:
dest_ns = int(self.options.dest_namespace)
@@ -196,6 +196,7 @@
dest_ns = None
for site in self.sites:
+ txt1 = source_text
if dest_ns is not None:
page2 = Page(site, page1.title(with_ns=False), dest_ns)
pywikibot.info('\nCross namespace, new title: '
diff --git a/tests/__init__.py b/tests/__init__.py
index b38fddb..7ec5c7e 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -199,6 +199,7 @@
'redirect_bot',
'reflinks',
'replacebot',
+ 'replicate_wiki',
'revertbot',
'script',
'speedy_delete',
diff --git a/tests/replicate_wiki_tests.py b/tests/replicate_wiki_tests.py
new file mode 100755
index 0000000..8d126d9
--- /dev/null
+++ b/tests/replicate_wiki_tests.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python3
+#
+# (C) Pywikibot team, 2026
+#
+# Distributed under the terms of the MIT license.
+#
+"""Tests for the replicate_wiki script."""
+from __future__ import annotations
+
+import unittest
+from collections import defaultdict
+from types import SimpleNamespace
+from unittest.mock import Mock, patch
+
+from scripts import replicate_wiki
+from tests.aspects import TestCase
+
+
+class TestSyncSites(TestCase):
+
+ """Test replication to multiple destination wikis."""
+
+ net = False
+ site = False
+
+ def test_replacements_are_per_destination(self) -> None:
+ """Apply each destination's replacements to the original text."""
+ bot = object.__new__(replicate_wiki.SyncSites)
+ bot.original = 'source'
+ bot.sites = ('first', 'second', 'unchanged')
+ bot.options = SimpleNamespace(dest_namespace=None, replace=True)
+ bot.differences = defaultdict(list)
+ bot.put_message = Mock(return_value='Sync summary')
+ pages = {
+ 'source': Mock(text='original'),
+ 'first': Mock(text='original'),
+ 'second': Mock(text='second text'),
+ 'unchanged': Mock(text='original'),
+ }
+ replacements = {
+ 'first': {'original': 'first text'},
+ 'second': {'original': 'second text'},
+ }
+
+ with patch.object(replicate_wiki, 'Page',
+ side_effect=lambda site, title: pages[site]), \
+ patch.object(replicate_wiki.config, 'replicate_replace',
+ replacements):
+ bot.check_page('Example')
+
+ self.assertEqual([pages[site].text for site in bot.sites],
+ ['first text', 'second text', 'original'])
+ self.assertEqual(bot.differences, {'first': ['Example']})
+
+
+if __name__ == '__main__':
+ unittest.main()
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1351401?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ia2041cf8b815d8a0599de4349f3106c0bdcd8d6e
Gerrit-Change-Number: 1351401
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]