jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655259 )
Change subject: [IMPR] Deprecate getuserinfo in favour of userinfo property
......................................................................
[IMPR] Deprecate getuserinfo in favour of userinfo property
Change-Id: I7195dc7d13d28eefb287ccd68bdd0ea9bdcd26d0
---
M pywikibot/site/__init__.py
1 file changed, 23 insertions(+), 8 deletions(-)
Approvals:
Mpaa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 127e828..c90883c 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -300,7 +300,7 @@
# or check user identity when OAuth enabled
self._loginstatus = _LoginStatus.IN_PROGRESS
try:
- self.getuserinfo(force=True)
+ del self.userinfo # force reload
if self.userinfo['name'] == self.user():
return
# May occur if you are not logged in (no API read permissions).
@@ -332,7 +332,8 @@
login_manager = api.LoginManager(site=self, user=self.username())
if login_manager.login(retry=True, autocreate=autocreate):
self._username = login_manager.username
- self.getuserinfo(force=True)
+ del self.userinfo # force reloading
+ self.userinfo # load userinfo
self._loginstatus = _LoginStatus.AS_USER
else:
self._loginstatus = _LoginStatus.NOT_LOGGED_IN # failure
@@ -375,9 +376,13 @@
# Clear also cookies for site's second level domain (T224712)
api._invalidate_superior_cookies(self.family)
- def getuserinfo(self, force=False):
+ @property
+ def userinfo(self):
"""Retrieve userinfo from site and store in _userinfo attribute.
+ To force retrieving userinfo ignoring cache, just delete this
+ property.
+
self._userinfo will be a dict with the following keys and values:
- id: user id (numeric str)
@@ -389,11 +394,8 @@
- blockinfo: present if user is blocked (dict)
U{https://www.mediawiki.org/wiki/API:Userinfo}
-
- @param force: force to retrieve userinfo ignoring cache
- @type force: bool
"""
- if force or not hasattr(self, '_userinfo'):
+ if not hasattr(self, '_userinfo'):
uirequest = self._simple_request(
action='query',
meta='userinfo',
@@ -410,7 +412,20 @@
.format(self))
return self._userinfo
- userinfo = property(fget=getuserinfo, doc=getuserinfo.__doc__)
+ @userinfo.deleter
+ def userinfo(self):
+ """Delete cached userinfo."""
+ del self._userinfo
+
+ @deprecated('userinfo property and userinfo deleter', since='20210110')
+ def getuserinfo(self, force: bool = False) -> dict:
+ """DEPRECATED. Retrieve userinfo from site.
+
+ @param force: force to retrieve userinfo ignoring cache
+ """
+ if force:
+ del self.userinfo
+ return self.userinfo
def getglobaluserinfo(self):
"""Retrieve globaluserinfo from site and cache it.
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655259
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7195dc7d13d28eefb287ccd68bdd0ea9bdcd26d0
Gerrit-Change-Number: 655259
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655266 )
Change subject: [IMPR] simplify TestClaimSetValue.test_set_musical_notation
......................................................................
[IMPR] simplify TestClaimSetValue.test_set_musical_notation
Change-Id: I7a532ec33e9fa757904a8db2b1430c1bb1851d9c
---
M tests/wikibase_tests.py
1 file changed, 4 insertions(+), 5 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 26ffc57..bd66528 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -1,7 +1,6 @@
-# -*- coding: utf-8 -*-
"""Tests for the Wikidata parts of the page module."""
#
-# (C) Pywikibot team, 2008-2020
+# (C) Pywikibot team, 2008-2021
#
# Distributed under the terms of the MIT license.
#
@@ -1685,9 +1684,9 @@
wikidata = self.get_repo()
claim = pywikibot.Claim(wikidata, 'P6604')
self.assertEqual(claim.type, 'musical-notation')
- claim.setTarget("\relative c' { c d e f | g2 g | a4 a a a | g1 |})")
- self.assertEqual(
- claim.target, "\relative c' { c d e f | g2 g | a4 a a a | g1 |})")
+ target = "\relative c' { c d e f | g2 g | a4 a a a | g1 |})"
+ claim.setTarget(target)
+ self.assertEqual(claim.target, target)
def test_set_incorrect_target_value(self):
"""Test setting claim of the incorrect value."""
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655266
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I7a532ec33e9fa757904a8db2b1430c1bb1851d9c
Gerrit-Change-Number: 655266
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655171 )
Change subject: Add support for "musical notation" data type to wikibase
......................................................................
Add support for "musical notation" data type to wikibase
Change-Id: Ie08cf3eff6e7808f6ef617dbaf286146f9990906
---
M pywikibot/page/__init__.py
M tests/wikibase_edit_tests.py
M tests/wikibase_tests.py
3 files changed, 30 insertions(+), 1 deletion(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py
index 2b85139..a7219dc 100644
--- a/pywikibot/page/__init__.py
+++ b/pywikibot/page/__init__.py
@@ -4692,6 +4692,7 @@
'external-id': str,
'geo-shape': pywikibot.WbGeoShape,
'tabular-data': pywikibot.WbTabularData,
+ 'musical-notation': str,
}
# the value type where different from the type
@@ -4704,6 +4705,7 @@
'external-id': 'string',
'geo-shape': 'string',
'tabular-data': 'string',
+ 'musical-notation': 'string',
}
def __init__(self, site, id: str, datatype: Optional[str] = None):
@@ -5381,7 +5383,8 @@
if self.type in ('wikibase-item', 'wikibase-property'):
value = {'entity-type': self.getTarget().entity_type,
'numeric-id': self.getTarget().getID(numeric=True)}
- elif self.type in ('string', 'url', 'math', 'external-id'):
+ elif self.type in ('string', 'url', 'math', 'external-id',
+ 'musical-notation'):
value = self.getTarget()
elif self.type == 'commonsMedia':
value = self.getTarget().title(with_ns=False)
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index a75fd81..53cd04a 100644
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -380,6 +380,23 @@
claim = item.claims['P30175'][0]
self.assertEqual(claim.getTarget(), target)
+ def test_musical_notation_edit(self):
+ """Attempt adding a musical notation claim with valid input."""
+ testsite = self.get_repo()
+ item = self._clean_item(testsite, 'P88936')
+
+ # set new claim
+ claim = pywikibot.page.Claim(
+ testsite, 'P88936', datatype='musical-notation')
+ target = "\relative c' { c d e f | g2 g | a4 a a a | g1 |})"
+ claim.setTarget(target)
+ item.addClaim(claim)
+
+ # confirm new claim
+ item.get(force=True)
+ claim = item.claims['P88936'][0]
+ self.assertEqual(claim.getTarget(), target)
+
class TestWikibaseRemoveQualifier(WikibaseTestCase):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 66be0bc..26ffc57 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -1680,6 +1680,15 @@
self.assertEqual(claim.target.month, 1)
self.assertEqual(claim.target.day, 1)
+ def test_set_musical_notation(self):
+ """Test setting claim of musical-notation type."""
+ wikidata = self.get_repo()
+ claim = pywikibot.Claim(wikidata, 'P6604')
+ self.assertEqual(claim.type, 'musical-notation')
+ claim.setTarget("\relative c' { c d e f | g2 g | a4 a a a | g1 |})")
+ self.assertEqual(
+ claim.target, "\relative c' { c d e f | g2 g | a4 a a a | g1 |})")
+
def test_set_incorrect_target_value(self):
"""Test setting claim of the incorrect value."""
wikidata = self.get_repo()
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/655171
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ie08cf3eff6e7808f6ef617dbaf286146f9990906
Gerrit-Change-Number: 655171
Gerrit-PatchSet: 1
Gerrit-Owner: Lokal Profil <andre.costa(a)wikimedia.se>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged