jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/333298 )
Change subject: [Bugfix] Access dictionary keys safely
......................................................................
[Bugfix] Access dictionary keys safely
When there is no claim of that property, this code fails with
a KeyError.
Change-Id: Ie969f583ae0c4780b44d0525d2887ec73c75ba58
---
M pywikibot/pagegenerators.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index fc5060c..29ddced 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1509,7 +1509,7 @@
if not isinstance(page, pywikibot.ItemPage):
pywikibot.output(u'%s is not an ItemPage. Skipping.' % page)
return False
- for page_claim in page.get()['claims'][prop]:
+ for page_claim in page.get()['claims'].get(prop, []):
if page_claim.target_equals(claim):
if not qualifiers:
return True
--
To view, visit https://gerrit.wikimedia.org/r/333298
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie969f583ae0c4780b44d0525d2887ec73c75ba58
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/333216 )
Change subject: pagegenerators_tests.py: Test that getCategory returns the correct site
......................................................................
pagegenerators_tests.py: Test that getCategory returns the correct site
0c33e28954b341ac32065198e5103d2ffa9b3eda fixed a bug that was causing
getCategory return a category from the wrong site (the default site instead
of the user-specified site). This patch adds a test for it.
Bug: T155687
Change-Id: I062a8af1c912ad6830cab81305d89cd34b873250
---
M tests/pagegenerators_tests.py
1 file changed, 16 insertions(+), 3 deletions(-)
Approvals:
jenkins-bot: Verified
Sn1per: Looks good to me, approved
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 77eba56..133caf8 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -2,12 +2,10 @@
# -*- coding: utf-8 -*-
"""Test pagegenerators module."""
#
-# (C) Pywikibot team, 2009-2016
+# (C) Pywikibot team, 2009-2017
#
# Distributed under the terms of the MIT license.
from __future__ import absolute_import, unicode_literals
-
-__version__ = '$Id$'
import calendar
import datetime
@@ -38,6 +36,9 @@
RecentChangesTestCase,
)
from tests.thread_tests import GeneratorIntersectTestCase
+
+
+__version__ = '$Id$'
en_wp_page_titles = (
# just a bunch of randomly selected titles for English Wikipedia tests
@@ -1110,6 +1111,18 @@
page2 = next(gen)
self.assertEqual(page2.title(), 'Q286874')
+ def test_get_category_site(self):
+ """Test the getCategory method."""
+ # With default site
+ gf = pagegenerators.GeneratorFactory()
+ cat = gf.getCategory('foo')[0]
+ self.assertEqual(cat.site, pywikibot.Site())
+ # With a user-specified site
+ fa_wikisource = pywikibot.Site('fa', 'wikisource')
+ gf = pagegenerators.GeneratorFactory(fa_wikisource)
+ cat = gf.getCategory('foo')[0]
+ self.assertEqual(cat.site, fa_wikisource)
+
class TestLogeventsFactoryGenerator(DefaultSiteTestCase,
DeprecationTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/333216
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I062a8af1c912ad6830cab81305d89cd34b873250
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Sn1per <geofbot(a)gmail.com>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>