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.
Conflicts: pywikibot/textlib.py tests/textlib_tests.py
Change-Id: Ibb39ea8b3079083feec93249eb6abe4b997feb74 (manually cherry picked from 64ffa4279fb1) --- M pywikibot/textlib.py M tests/textlib_tests.py 2 files changed, 17 insertions(+), 5 deletions(-)
Approvals: XZise: Looks good to me, approved Merlijn van Deen: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py index b40aba4..e08560d 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -686,14 +686,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.lang in insite.family.interwiki_on_one_line: sep = u' ' else: diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index 468d3f2..e6821e3 100644 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -90,7 +90,8 @@
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)), 'fr': pywikibot.Page(pywikibot.Link('fr:French', self.site)) @@ -99,6 +100,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):