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

Change subject: interwiki: Use pywikibot.link_regex pattern for hintfile
......................................................................

interwiki: Use pywikibot.link_regex pattern for hintfile

Also add tests for -hint and -hintfile option

Change-Id: I66cb63331639f2fb77a43d0fe966e5ee02a0f553
---
M scripts/interwiki.py
M tests/interwikibot_tests.py
2 files changed, 13 insertions(+), 3 deletions(-)

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




diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 2708bc9..1ae839d 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -520,10 +520,9 @@
         elif arg == 'hintfile':
             hintfilename = value or pywikibot.input(
                 'Please enter the hint filename:')
-            # hint or title ends either before | or before ]]
-            R = re.compile(r'\[\[(.+?)(?:\]\]|\|)')
             txt = Path(hintfilename).read_text(config.textfile_encoding)
-            self.hints += R.findall(txt)
+            self.hints.extend(m['title']
+                              for m in pywikibot.link_regex.finditer(txt))
         elif arg == 'untranslatedonly':
             self.untranslated = True
             self.untranslatedonly = True
diff --git a/tests/interwikibot_tests.py b/tests/interwikibot_tests.py
index 0a463e1..b0a0e8d 100755
--- a/tests/interwikibot_tests.py
+++ b/tests/interwikibot_tests.py
@@ -33,6 +33,17 @@
         site = DrySite(code, fam, None)
         return site

+    def test_hint_options(self):
+        """Test -hint and -hintfile options."""
+        iwc = interwiki.InterwikiBotConfig()
+        self.assertIsInstance(iwc.hints, list)
+        self.assertIsEmpty(iwc.hints)
+        iwc.readOptions('-hintfile:tests/data/pagelist-brackets.txt')
+        self.assertLength(iwc.hints, 5)
+        for option in '-hint:foo -hint:bar -hint:baz'.split():
+            iwc.readOptions(option)
+        self.assertLength(iwc.hints, 8)
+
     def test_ignore_option(self):
         """Test -ignore and -ignorefile options."""
         iwc = interwiki.InterwikiBotConfig()

--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1306103?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: I66cb63331639f2fb77a43d0fe966e5ee02a0f553
Gerrit-Change-Number: 1306103
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[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