jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/421701 )
Change subject: Make sure interwiki title is parsed in textlib.getLanguageLinks
......................................................................
Make sure interwiki title is parsed in textlib.getLanguageLinks
The try-except block was redundant because InvalidTitle is raised
when the title is parsed, not just constructed.
Change-Id: I34b0265acae52ad5bb9e5e38cf2f84d92bb2bdf5
---
M pywikibot/textlib.py
M tests/textlib_tests.py
2 files changed, 15 insertions(+), 9 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 2be1ea8..7a40a55 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -861,17 +861,18 @@
# skip language links to its own site
if site == insite:
continue
+ previous_key_count = len(result)
+ page = pywikibot.Page(site, pagetitle)
try:
- previous_key_count = len(result)
- result[site] = pywikibot.Page(site, pagetitle)
- if previous_key_count == len(result):
- pywikibot.warning('[getLanguageLinks] 2 or more interwiki '
- 'links point to site %s.' % site)
+ result[page.site] = page # need to trigger page._link.parse()
except InvalidTitle:
- pywikibot.output(u'[getLanguageLinks] Text contains invalid '
- u'interwiki link [[%s:%s]].'
+ pywikibot.output('[getLanguageLinks] Text contains invalid '
+ 'interwiki link [[%s:%s]].'
% (lang, pagetitle))
continue
+ if previous_key_count == len(result):
+ pywikibot.warning('[getLanguageLinks] 2 or more interwiki '
+ 'links point to site %s.' % site)
return result
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py
index 45e09ef..ca49ada 100644
--- a/tests/textlib_tests.py
+++ b/tests/textlib_tests.py
@@ -1472,7 +1472,8 @@
},
}
- example_text = '[[en:Site]] [[de:Site|Piped]] [[commons:Site]] [[baden:Site]]'
+ example_text = ('[[en:Site]] [[de:Site|Piped]] [[commons:Site]] '
+ '[[baden:Site]] [[fr:{{PAGENAME}}]]')
@classmethod
def setUpClass(cls):
@@ -1482,7 +1483,11 @@
def test_getLanguageLinks(self, key):
"""Test if the function returns the correct titles and sites."""
- lang_links = textlib.getLanguageLinks(self.example_text, self.site)
+ with mock.patch('pywikibot.output') as m:
+ lang_links = textlib.getLanguageLinks(self.example_text, self.site)
+ m.assert_called_once_with(
+ '[getLanguageLinks] Text contains invalid interwiki link '
+ '[[fr:{{PAGENAME}}]].')
self.assertEqual(set(page.title() for page in lang_links.values()),
set(['Site']))
self.assertEqual(set(lang_links), self.sites_set - set([self.site]))
--
To view, visit https://gerrit.wikimedia.org/r/421701
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I34b0265acae52ad5bb9e5e38cf2f84d92bb2bdf5
Gerrit-Change-Number: 421701
Gerrit-PatchSet: 3
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dvorapa <dvorapa(a)seznam.cz>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/421539 )
Change subject: Make sure entites are preloaded on a DataSite
......................................................................
Make sure entites are preloaded on a DataSite
This resulted in AttributeError.
Change-Id: Iab08428441c35d8b762a55e89e8b182f3a47245e
---
M pywikibot/pagegenerators.py
M tests/pagegenerators_tests.py
M tests/wikibase_tests.py
3 files changed, 30 insertions(+), 11 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 55a5c1b..aeddfe5 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2081,6 +2081,7 @@
Function basically is copied from above, but for Wikibase entities.
@param generator: pages to iterate over
+ @type generator: Iterable
@param groupsize: how many pages to preload at once
@type groupsize: int
"""
@@ -2091,11 +2092,13 @@
if len(sites[site]) >= groupsize:
# if this site is at the groupsize, process it
group = sites.pop(site)
- for i in site.preload_entities(group, groupsize):
+ repo = site.data_repository()
+ for i in repo.preload_entities(group, groupsize):
yield i
for site, pages in sites.items():
# process any leftover sites that never reached the groupsize
- for i in site.preload_entities(pages, groupsize):
+ repo = site.data_repository()
+ for i in repo.preload_entities(pages, groupsize):
yield i
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 43ca6ce..d8d5a0c 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -600,16 +600,16 @@
self.assertTrue(pages_out[1].isTalkPage())
-class TestPreloadingItemGenerator(WikidataTestCase):
+class TestPreloadingEntityGenerator(WikidataTestCase):
"""Test preloading item generator."""
def test_non_item_gen(self):
- """Test TestPreloadingItemGenerator with ReferringPageGenerator."""
+ """Test TestPreloadingEntityGenerator with ReferringPageGenerator."""
site = self.get_site()
instance_of_page = pywikibot.Page(site, 'Property:P31')
ref_gen = pagegenerators.ReferringPageGenerator(instance_of_page, total=5)
- gen = pagegenerators.PreloadingItemGenerator(ref_gen)
+ gen = pagegenerators.PreloadingEntityGenerator(ref_gen)
self.assertTrue(all(isinstance(item, pywikibot.ItemPage) for item in gen))
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index f6bb342..2fc7fee 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -1647,19 +1647,35 @@
self.assertEqual(response, self.data_out)
-class TestPreloadingItemGenerator(TestCase):
+class TestPreloadingEntityGenerator(TestCase):
"""Test preloading item generator."""
- family = 'wikidata'
- code = 'wikidata'
+ sites = {
+ 'wikidata': {
+ 'family': 'wikidata',
+ 'code': 'wikidata',
+ },
+ 'enwiki': {
+ 'family': 'wikipedia',
+ 'code': 'en',
+ }
+ }
def test_non_item_gen(self):
- """Test TestPreloadingItemGenerator with ReferringPageGenerator."""
- site = self.get_site()
+ """Test PreloadingEntityGenerator with ReferringPageGenerator."""
+ site = self.get_site('wikidata')
instance_of_page = pywikibot.Page(site, 'Property:P31')
ref_gen = pagegenerators.ReferringPageGenerator(instance_of_page, total=5)
- gen = pagegenerators.PreloadingItemGenerator(ref_gen)
+ gen = pagegenerators.PreloadingEntityGenerator(ref_gen)
+ self.assertTrue(all(isinstance(item, ItemPage) for item in gen))
+
+ def test_foreign_page_item_gen(self):
+ """Test PreloadingEntityGenerator with connected pages."""
+ site = self.get_site('enwiki')
+ page_gen = [pywikibot.Page(site, 'Main Page'),
+ pywikibot.Page(site, 'New York City')]
+ gen = pagegenerators.PreloadingEntityGenerator(page_gen)
self.assertTrue(all(isinstance(item, ItemPage) for item in gen))
--
To view, visit https://gerrit.wikimedia.org/r/421539
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iab08428441c35d8b762a55e89e8b182f3a47245e
Gerrit-Change-Number: 421539
Gerrit-PatchSet: 4
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/421056 )
Change subject: tools/__init__.py: Add param info to issue_deprecation_warning.__doc__
......................................................................
tools/__init__.py: Add param info to issue_deprecation_warning.__doc__
Change-Id: Ib302125e8da2d689ebddfdff2890f18d3b321cd3
---
M pywikibot/tools/__init__.py
1 file changed, 12 insertions(+), 1 deletion(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 376f1b4..8dba207 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -1356,7 +1356,18 @@
def issue_deprecation_warning(name, instead, depth, warning_class=None):
- """Issue a deprecation warning."""
+ """Issue a deprecation warning.
+
+ @param name: the name of the deprecated object
+ @type name: str
+ @param instead: suggested replacement for the deprecated object
+ @type instead: str
+ @param depth: depth + 1 will be used as stacklevel for the warnings
+ @type depth: int
+ @param warning_class: a warning class (category) to be used, defaults to
+ DeprecationWarning
+ @type warning_class: type
+ """
if instead:
if warning_class is None:
warning_class = DeprecationWarning
--
To view, visit https://gerrit.wikimedia.org/r/421056
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib302125e8da2d689ebddfdff2890f18d3b321cd3
Gerrit-Change-Number: 421056
Gerrit-PatchSet: 2
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Zoranzoki21 <zorandori4444(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>