jenkins-bot has submitted this change and it was merged.
Change subject: Fix interwikiFormat support for Link
......................................................................
Fix interwikiFormat support for Link
interwikiFormat is supposed to support a dictionary of Page or Link
objects. There were several merges of core and compat 'textlib' to
keep the two in sync, such as core's 8978bfb6, and the support for
Link was broken somewhere along the way.
Add tests for Link in addition to existing tests for Page.
Also add a ValueError exception if it contains any other type.
Change-Id: Ibb39ea8b3079083feec93249eb6abe4b997feb74
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 16 insertions(+), 5 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 18b9d7d..5998ac0 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -941,14 +941,15 @@
ar = interwikiSort(list(links.keys()), insite)
s = []
for site in ar:
- try:
+ if isinstance(links[site], pywikibot.Link):
+ links[site] = pywikibot.Page(links[site])
+ if isinstance(links[site], pywikibot.Page):
title = links[site].title(asLink=True, forceInterwiki=True,
insite=insite)
link = title.replace('[[:', '[[')
s.append(link)
- except AttributeError:
- s.append(pywikibot.Site(site, insite.family).linkto(
- links[site], othersite=insite))
+ else:
+ raise ValueError('links dict must contain Page or Link objects')
if insite.code in insite.family.interwiki_on_one_line:
sep = u' '
else:
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index ff37a56..e50d5ef 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -104,7 +104,7 @@
cached = True
- def test_interwiki_format(self):
+ def test_interwiki_format_Page(self):
"""Test formatting interwiki links using Page
instances."""
interwikis = {
'de': pywikibot.Page(pywikibot.Link('de:German',
self.site)),
@@ -114,6 +114,16 @@
% {'LS': config.LS},
textlib.interwikiFormat(interwikis, self.site))
+ def test_interwiki_format_Link(self):
+ """Test formatting interwiki links using Page
instances."""
+ interwikis = {
+ 'de': pywikibot.Link('de:German', self.site),
+ 'fr': pywikibot.Link('fr:French', self.site),
+ }
+ self.assertEqual('[[de:German]]%(LS)s[[fr:French]]%(LS)s'
+ % {'LS': config.LS},
+ textlib.interwikiFormat(interwikis, self.site))
+
class TestFormatCategory(DefaultDrySiteTestCase):
--
To view, visit
https://gerrit.wikimedia.org/r/240649
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibb39ea8b3079083feec93249eb6abe4b997feb74
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>