XZise has submitted this change and it was merged.
Change subject: PropertyPage.get() fails
......................................................................
PropertyPage.get() fails
PropertyPage method get attempts to set 'type', which is a
property of superclass Property that does not have a setter, resulting
in an AttributeError:
self.type = self._content['datatype']
AttributeError: can't set attribute
Fix by putting the datatype into the underlying _type attribute.
Also use the 'type' property in PropertyPage.newClaim so that each newly
created Claim does not need to fetch the property type.
Change-Id: I845ec3ad91017e386e568ee5bcb85fd48644adfb
---
M pywikibot/page.py
M tests/wikibase_tests.py
2 files changed, 22 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
diff --git a/pywikibot/page.py b/pywikibot/page.py
index fb5bffe..8052f0b 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3172,7 +3172,7 @@
"""
if force or not hasattr(self, '_content'):
WikibasePage.get(self, force=force, *args)
- self.type = self._content['datatype']
+ self._type = self._content['datatype']
def newClaim(self, *args, **kwargs):
"""
@@ -3180,7 +3180,8 @@
@return: Claim
"""
- return Claim(self.site, self.getID(), *args, **kwargs)
+ return Claim(self.site, self.getID(), datatype=self.type,
+ *args, **kwargs)
class Claim(Property):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index a9142dd..67df427 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -384,6 +384,25 @@
self.assertEquals(claim.type, 'globe-coordinate')
self.assertEquals(claim.getType(), 'globecoordinate')
+ def test_get(self):
+ property_page = pywikibot.PropertyPage(wikidata, 'P625')
+ property_page.get()
+ self.assertEquals(property_page.type, 'globe-coordinate')
+
+ def test_new_claim(self):
+ """Test that PropertyPage.newClaim uses cached datatype."""
+ property_page = pywikibot.PropertyPage(wikidata, 'P625')
+ property_page.get()
+ claim = property_page.newClaim()
+ self.assertEquals(claim.type, 'globe-coordinate')
+
+ # Now verify that it isnt fetching the type from the property
+ # data in the repo by setting the cache to the incorrect type
+ # and checking that it is the cached value that is used.
+ property_page._type = 'wikibase-item'
+ claim = property_page.newClaim()
+ self.assertEquals(claim.type, 'wikibase-item')
+
class TestClaimSetValue(PywikibotTestCase):
--
To view, visit https://gerrit.wikimedia.org/r/154012
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I845ec3ad91017e386e568ee5bcb85fd48644adfb
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits