jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631386 )
Change subject: [bugfix] Fix errors which occurred due to missing
Family.version()
......................................................................
[bugfix] Fix errors which occurred due to missing Family.version()
- remove family.force_version which was never used and its implementation
is unclear.
- remove force_version call in APISite.version() which always gave None
- remove Family.version() fallback in APISite.version() and raise the
exception
- print an error message and raise the exception if the version info
could not retrieved via api
- use Site.mw_version in favour of Site.version() within bot.py
api_tests.py:
- remove suppress_warnings decorators for removed Family.version() method
- update test_access_denied_no_username and
test_access_denied_notexist_username accordingly
Bug: T264096
Change-Id: I71fb62f52ccd0176280c86b88ac037c3355df3e9
---
M pywikibot/bot.py
M pywikibot/family.py
M pywikibot/site/__init__.py
M tests/api_tests.py
4 files changed, 22 insertions(+), 61 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index da21a7f..abf756f 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1428,15 +1428,14 @@
return
if site not in self._sites:
- log('LOADING SITE %s VERSION: %s'
- % (site, site.version()))
+ log('LOADING SITE {} VERSION: {}'.format(site, site.mw_version))
self._sites.add(site)
if len(self._sites) == 2:
- log('%s uses multiple sites' % self.__class__.__name__)
+ log('{} uses multiple sites'.format(self.__class__.__name__))
if self._site and self._site != site:
- log('%s: changing site from %s to %s'
- % (self.__class__.__name__, self._site, site))
+ log('{}: changing site from {} to {}'
+ .format(self.__class__.__name__, self._site, site))
self._site = site
def run(self):
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 55b77ed..22d3078 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1034,26 +1034,6 @@
"""Return the name of the MySQL database."""
return '%s%s' % (code, self.name)
- def force_version(self, code):
- """
- Return a manual version number.
-
- The site is usually using the version number from the servers'
- siteinfo, but if there is a problem with that it's possible to return
- a non-empty string here representing another version number.
-
- For example, L{pywikibot.tools.MediaWikiVersion} treats version
- numbers ending with 'alpha', 'beta' or 'rc' as newer than any version
- ending with 'wmf<number>'. But if that causes breakage it's possible
- to override it here to a version number which doesn't cause breakage.
-
- @return: A version number which can be parsed using
- L{pywikibot.tools.MediaWikiVersion}. If empty/None it uses the
- version returned via siteinfo.
- @rtype: str
- """
- return None
-
def encoding(self, code):
"""Return the encoding for a specific language wiki."""
return 'utf-8'
diff --git a/pywikibot/site/__init__.py b/pywikibot/site/__init__.py
index 1f6f804..65b212e 100644
--- a/pywikibot/site/__init__.py
+++ b/pywikibot/site/__init__.py
@@ -2102,24 +2102,20 @@
return self.siteinfo['lang']
def version(self):
- """
- Return live project version number as a string.
+ """Return live project version number as a string.
- This overwrites the corresponding family method for APISite class. Use
- L{pywikibot.site.mw_version} to compare MediaWiki versions.
+ Use L{pywikibot.site.mw_version} to compare MediaWiki versions.
"""
- version = self.force_version()
- if not version:
- try:
- version = self.siteinfo.get('generator',
- expiry=1).split(' ')[1]
- except pywikibot.data.api.APIError:
- # May occur if you are not logged in (no API read permissions).
- pywikibot.exception('You have no API read permissions. Seems '
- 'you are not logged in')
- version = self.family.version(self.code)
+ try:
+ version = self.siteinfo.get('generator', expiry=1).split(' ')[1]
+ except pywikibot.data.api.APIError:
+ msg = 'You have no API read permissions.'
+ if not self.logged_in():
+ msg += ' Seems you are not logged in.'
+ pywikibot.error(msg)
+ raise
- if MediaWikiVersion(version) < MediaWikiVersion('1.19'):
+ if MediaWikiVersion(version) < '1.19':
raise RuntimeError(
'Pywikibot "{}" does not support MediaWiki "{}".\n'
'Use Pywikibot prior to "5.0" or "python2" branch '
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 1774800..9895f52 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -994,33 +994,21 @@
pywikibot.data.api.LoginManager = self.orig_login_manager
super(TestLazyLoginNotExistUsername, self).tearDown()
- # When there is no API access the deprecated family.version is used.
- @suppress_warnings('pywikibot.family.Family.version is deprecated')
@patch.object(pywikibot, 'output')
- @patch.object(pywikibot, 'exception')
@patch.object(pywikibot, 'warning')
@patch.object(pywikibot, 'error')
- def test_access_denied_notexist_username(
- self, error, warning, exception, output
- ):
+ def test_access_denied_notexist_username(self, error, warning, output):
"""Test the query with a username which does not exist."""
self.site._username = 'Not registered username'
req = api.Request(site=self.site, parameters={'action': 'query'})
self.assertRaises(pywikibot.NoUsername, req.submit)
# FIXME: T100965
self.assertRaises(api.APIError, req.submit)
- try:
- error.assert_called_with('Login failed (readapidenied).')
- except AssertionError: # MW version is older than 1.34.0-wmf.13
- try:
- error.assert_called_with('Login failed (FAIL).')
- except AssertionError: # MW version is older than 1.27
- error.assert_called_with('Login failed (Failed).')
warning.assert_called_with(
'API error readapidenied: '
'You need read permission to use this module.')
- exception.assert_called_with(
- 'You have no API read permissions. Seems you are not logged in')
+ error.assert_called_with(
+ 'You have no API read permissions. Seems you are not logged in.')
self.assertIn(
'Logging in to steward:steward as ', output.call_args[0][0])
@@ -1029,12 +1017,10 @@
"""Test no username."""
- # When there is no API access the deprecated family.version is used.
- @suppress_warnings('pywikibot.family.Family.version is deprecated')
@patch.object(pywikibot, 'warning')
- @patch.object(pywikibot, 'exception')
+ @patch.object(pywikibot, 'error')
@patch.object(pywikibot.config, 'usernames', defaultdict(dict))
- def test_access_denied_no_username(self, exception, warning):
+ def test_access_denied_no_username(self, error, warning):
"""Test the query without a username."""
self.site._username = None
req = api.Request(site=self.site, parameters={'action': 'query'})
@@ -1044,8 +1030,8 @@
warning.assert_called_with(
'API error readapidenied: '
'You need read permission to use this module.')
- exception.assert_called_with(
- 'You have no API read permissions. Seems you are not logged in')
+ error.assert_called_with(
+ 'You have no API read permissions. Seems you are not logged in.')
class TestBadTokenRecovery(TestCase):
--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/631386
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: I71fb62f52ccd0176280c86b88ac037c3355df3e9
Gerrit-Change-Number: 631386
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: JJMC89 <[email protected]>
Gerrit-Reviewer: Matěj Suchánek <[email protected]>
Gerrit-Reviewer: Mpaa <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits