jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1335015?usp=email )

Change subject: reflinks: Skip adding references to templates
......................................................................

reflinks: Skip adding references to templates

Call Page.namespace() instead of comparing its bound method with the
template namespace number. This makes the existing template exclusion
effective.

Change-Id: Ia8b036053d712b0b7f4960f935841e04151d665d
---
M scripts/reflinks.py
M tests/reflinks_tests.py
2 files changed, 22 insertions(+), 2 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved




diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 3927a2b..52333b7 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -704,7 +704,7 @@
             new_text = new_text.replace(match.group(), repl)

         # Add <references/> when needed, but ignore templates !
-        if page.namespace != 10 and self.norefbot.lacksReferences(new_text):
+        if page.namespace() != 10 and self.norefbot.lacksReferences(new_text):
             new_text = self.norefbot.addReferences(new_text)

         new_text = self.deduplicator.process(new_text)
diff --git a/tests/reflinks_tests.py b/tests/reflinks_tests.py
index a35e0b2..ddf4ecd 100755
--- a/tests/reflinks_tests.py
+++ b/tests/reflinks_tests.py
@@ -9,7 +9,7 @@

 import unittest
 from types import SimpleNamespace
-from unittest.mock import patch
+from unittest.mock import Mock, patch

 from scripts.reflinks import ReferencesRobot, XmlDumpPageGenerator, main
 from tests import join_xml_data_path
@@ -41,6 +41,26 @@
             capture_output=True, check=False)


+class TestReferencesRobot(TestCase):
+
+    """Tests for the reflinks bot."""
+
+    net = False
+
+    def test_template_does_not_add_references(self) -> None:
+        """Test that references are not added to template pages."""
+        bot = object.__new__(ReferencesRobot)
+        bot.norefbot = Mock()
+        bot.norefbot.lacksReferences.return_value = False
+        bot.deduplicator = Mock()
+        bot.deduplicator.process.side_effect = lambda text: text
+        page = SimpleNamespace(text='', namespace=lambda: 10)
+
+        bot.treat(page)
+
+        bot.norefbot.lacksReferences.assert_not_called()
+
+
 class TestXMLPageGenerator(TestCase):

     """Test XML Page generator."""

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1335015?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: Ia8b036053d712b0b7f4960f935841e04151d665d
Gerrit-Change-Number: 1335015
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]

Reply via email to