jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/463089 )
Change subject: [cleanup] cleanup tests/[user_tests.py to wikibase_edit_tests.py]
......................................................................
[cleanup] cleanup tests/[user_tests.py to wikibase_edit_tests.py]
- use str.format(...) instead of modulo for type specifier
arguments.
- use single quotes for string literals
- remove preleading "u" fron strings
- indentation to make sure code lines are less than 79
characters.
Change-Id: Ibfe2f35a877e4074ce67619a0c4ce7a868e53985
---
M tests/utils.py
M tests/weblib_tests.py
M tests/weblinkchecker_tests.py
M tests/wikibase_edit_tests.py
4 files changed, 36 insertions(+), 28 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/utils.py b/tests/utils.py
index 84ce7bf..e9b7cf9 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -255,10 +255,10 @@
"""
Context manager to assert certain APIError exceptions.
- This is build similar to the L{unittest.TestCase.assertError} implementation
- which creates an context manager. It then calls L{handle} which either
- returns this manager if no executing object given or calls the callable
- object.
+ This is build similar to the L{unittest.TestCase.assertError}
+ implementation which creates an context manager. It then calls L{handle}
+ which either returns this manager if no executing object given or calls
+ the callable object.
"""
def __init__(self, code, info, msg, test_case):
@@ -392,8 +392,8 @@
def submit(self):
"""Prevented method."""
- raise Exception(u'DryRequest rejecting request: %r'
- % self._params)
+ raise Exception('DryRequest rejecting request: {!r}'
+ .format(self._params))
class DrySite(pywikibot.site.APISite):
@@ -558,9 +558,9 @@
This patches the C{http} import in the given module to a class simulating
C{request} and C{fetch}. It has a C{data} attribute which is either a
- static value which the requests will return or it's a callable returning the
- data. If it's a callable it'll be called with the same parameters as the
- original function in the L{http} module. For fine grained control it's
+ static value which the requests will return or it's a callable returning
+ the data. If it's a callable it'll be called with the same parameters as
+ the original function in the L{http} module. For fine grained control it's
possible to override/monkey patch the C{before_request} and C{before_fetch}
methods. By default they just return C{data} directory or call it if it's
callable.
@@ -680,14 +680,15 @@
not isinstance(v, str)]
if unicode_env:
raise TypeError(
- '%s: unicode in os.environ: %r' % (e, unicode_env))
+ '{}: unicode in os.environ: {!r}'.format(e, unicode_env))
child_unicode_env = [(k, v) for k, v in env.items()
if not isinstance(k, str) or
not isinstance(v, str)]
if child_unicode_env:
raise TypeError(
- '%s: unicode in child env: %r' % (e, child_unicode_env))
+ '{}: unicode in child env: {!r}'
+ .format(e, child_unicode_env))
raise
if data_in is not None:
@@ -718,7 +719,8 @@
data_out = p.communicate()
return {'exit_code': p.returncode,
'stdout': data_out[0].decode(config.console_encoding),
- 'stderr': (stderr_lines + data_out[1]).decode(config.console_encoding)}
+ 'stderr': (stderr_lines + data_out[1])
+ .decode(config.console_encoding)}
def execute_pwb(args, data_in=None, timeout=0, error=None, overrides=None):
@@ -735,10 +737,10 @@
if overrides:
command.append('-c')
overrides = '; '.join(
- '%s = %s' % (key, value) for key, value in overrides.items())
+ '{} = {}'.format(key, value) for key, value in overrides.items())
command.append(
- 'import pwb; import pywikibot; %s; pwb.main()'
- % overrides)
+ 'import pwb; import pywikibot; {}; pwb.main()'
+ .format(overrides))
else:
command.append(_pwb_py)
diff --git a/tests/weblib_tests.py b/tests/weblib_tests.py
index a16e441..98d657b 100644
--- a/tests/weblib_tests.py
+++ b/tests/weblib_tests.py
@@ -50,17 +50,20 @@
"""Test Internet Archive for newest https://google.com."""
archivedversion = self._get_archive_url('https://google.com')
parsed = urlparse(archivedversion)
- self.assertIn(parsed.scheme, [u'http', u'https'])
- self.assertEqual(parsed.netloc, u'web.archive.org')
- self.assertTrue(parsed.path.strip('/').endswith('google.com'), parsed.path)
+ self.assertIn(parsed.scheme, ['http', 'https'])
+ self.assertEqual(parsed.netloc, 'web.archive.org')
+ self.assertTrue(parsed.path.strip('/').endswith('google.com'),
+ parsed.path)
def testInternetArchiveOlder(self):
"""Test Internet Archive for https://google.com as of June 2006."""
- archivedversion = self._get_archive_url('https://google.com', '20060601')
+ archivedversion = self._get_archive_url('https://google.com',
+ '20060601')
parsed = urlparse(archivedversion)
- self.assertIn(parsed.scheme, [u'http', u'https'])
- self.assertEqual(parsed.netloc, u'web.archive.org')
- self.assertTrue(parsed.path.strip('/').endswith('google.com'), parsed.path)
+ self.assertIn(parsed.scheme, ['http', 'https'])
+ self.assertEqual(parsed.netloc, 'web.archive.org')
+ self.assertTrue(parsed.path.strip('/').endswith('google.com'),
+ parsed.path)
self.assertIn('200606', parsed.path)
@@ -82,8 +85,10 @@
@unittest.expectedFailure # See T110640
def testWebCiteOlder(self):
"""Test WebCite for https://google.com as of January 2013."""
- archivedversion = self._get_archive_url('https://google.com', '20130101')
- self.assertEqual(archivedversion, 'http://www.webcitation.org/6DHSeh2L0')
+ archivedversion = self._get_archive_url('https://google.com',
+ '20130101')
+ self.assertEqual(archivedversion,
+ 'http://www.webcitation.org/6DHSeh2L0')
if __name__ == '__main__': # pragma: no cover
diff --git a/tests/weblinkchecker_tests.py b/tests/weblinkchecker_tests.py
index 8052d63..4608723 100644
--- a/tests/weblinkchecker_tests.py
+++ b/tests/weblinkchecker_tests.py
@@ -42,7 +42,8 @@
self.skipTest(e)
-class WeblibTestMementoInternetArchive(MementoTestCase, weblib_tests.TestInternetArchive):
+class WeblibTestMementoInternetArchive(MementoTestCase,
+ weblib_tests.TestInternetArchive):
"""Test InternetArchive Memento using old weblib tests."""
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index 3f1cf59..497cfa1 100644
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -402,7 +402,7 @@
# Remove qualifier
claim = item.claims['P115'][0]
- qual_3 = claim.qualifiers[u'P580'][0]
+ qual_3 = claim.qualifiers['P580'][0]
claim.removeQualifier(qual_3)
# Check P580 qualifier removed but P88 qualifier remains
@@ -422,8 +422,8 @@
# Remove qualifiers
item.get(force=True)
claim = item.claims['P115'][0]
- qual_3 = claim.qualifiers[u'P580'][0]
- qual_4 = claim.qualifiers[u'P88'][0]
+ qual_3 = claim.qualifiers['P580'][0]
+ qual_4 = claim.qualifiers['P88'][0]
claim.removeQualifiers([qual_3, qual_4])
# Check P580 and P88 qualifiers are removed
--
To view, visit https://gerrit.wikimedia.org/r/463089
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibfe2f35a877e4074ce67619a0c4ce7a868e53985
Gerrit-Change-Number: 463089
Gerrit-PatchSet: 3
Gerrit-Owner: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462913 )
Change subject: [cleanup] cleanup scripts/maintenance/compat2core.py
......................................................................
[cleanup] cleanup scripts/maintenance/compat2core.py
- remove preleading "u" from strings
- use single quotes for string literals
- use str.format(...) instead of modulo for substituting
type specifier arguments with placeholders
Change-Id: Ie30db8720ed37861e42b76a4e6b2ddfda8ee5ca4
---
M scripts/maintenance/compat2core.py
1 file changed, 7 insertions(+), 6 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/compat2core.py b/scripts/maintenance/compat2core.py
index cfc807d..00afe9d 100755
--- a/scripts/maintenance/compat2core.py
+++ b/scripts/maintenance/compat2core.py
@@ -56,7 +56,7 @@
('import catlib\r?\n', ''),
('import userlib\r?\n', ''),
# change wikipedia to pywikibot, exclude URLs
- (r'(?<!\.)wikipedia\.', u'pywikibot.'),
+ (r'(?<!\.)wikipedia\.', 'pywikibot.'),
# site instance call
(r'pywikibot\.getSite\s*\(\s*', 'pywikibot.Site('),
# lang is different from code. We should use code in core
@@ -152,21 +152,22 @@
'(no input to leave):')
if not self.source:
exit()
- if not self.source.endswith(u'.py'):
+ if not self.source.endswith('.py'):
self.source += '.py'
if os.path.exists(self.source):
break
self.source = os.path.join('scripts', self.source)
if os.path.exists(self.source):
break
- pywikibot.output(u'%s does not exist. Please retry.' % self.source)
+ pywikibot.output('{} does not exist. Please retry.'
+ .format(self.source))
self.source = None
def get_dest(self):
"""Ask for destination script name."""
- self.dest = u'%s-core.%s' % tuple(self.source.rsplit(u'.', 1))
+ self.dest = '%s-core.%s' % tuple(self.source.rsplit('.', 1))
if not self.warnonly and not pywikibot.input_yn(
- u'Destination file is %s.' % self.dest,
+ 'Destination file is {}.'.format(self.dest),
default=True, automatic_quit=False):
pywikibot.output('Quitting...')
exit()
@@ -209,6 +210,6 @@
bot.run()
-if __name__ == "__main__":
+if __name__ == '__main__':
pywikibot.stopme() # we do not work on any site
main()
--
To view, visit https://gerrit.wikimedia.org/r/462913
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie30db8720ed37861e42b76a4e6b2ddfda8ee5ca4
Gerrit-Change-Number: 462913
Gerrit-PatchSet: 1
Gerrit-Owner: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462764 )
Change subject: [cleanup] cleanup scripts/commonscat.py
......................................................................
[cleanup] cleanup scripts/commonscat.py
- use str.format(...) instead of modulo for type specifier
arguments.
- use single quotes for string literals
- use "+" for concatenating strings in some cases
Change-Id: I303434ee78d2b0c4b04d95eabf43338d78973364
---
M scripts/commonscat.py
1 file changed, 23 insertions(+), 22 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index 1ad4a1f..71a95cf 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -241,17 +241,17 @@
def treat(self, page):
"""Load the given page, do some changes, and save it."""
if not page.exists():
- pywikibot.output('Page %s does not exist. Skipping.'
- % page.title(as_link=True))
+ pywikibot.output('Page {} does not exist. Skipping.'
+ .format(page.title(as_link=True)))
elif page.isRedirectPage():
- pywikibot.output('Page %s is a redirect. Skipping.'
- % page.title(as_link=True))
+ pywikibot.output('Page {} is a redirect. Skipping.'
+ .format(page.title(as_link=True)))
elif page.isCategoryRedirect():
- pywikibot.output('Page %s is a category redirect. Skipping.'
- % page.title(as_link=True))
+ pywikibot.output('Page {} is a category redirect. Skipping.'
+ .format(page.title(as_link=True)))
elif page.isDisambig():
- pywikibot.output('Page %s is a disambiguation. Skipping.'
- % page.title(as_link=True))
+ pywikibot.output('Page {} is a disambiguation. Skipping.'
+ .format(page.title(as_link=True)))
else:
self.addCommonscat(page)
@@ -265,7 +265,7 @@
if code in commonscatTemplates:
return commonscatTemplates[code]
else:
- return commonscatTemplates[u'_default']
+ return commonscatTemplates['_default']
def skipPage(self, page):
"""Determine if the page should be skipped."""
@@ -299,16 +299,17 @@
page.site.code)
commonscatLink = self.getCommonscatLink(page)
if commonscatLink:
- pywikibot.output('Commonscat template is already on %s'
- % page.title())
+ pywikibot.output('Commonscat template is already on '
+ + page.title())
(currentCommonscatTemplate,
currentCommonscatTarget, LinkText, Note) = commonscatLink
checkedCommonscatTarget = self.checkCommonscatLink(
currentCommonscatTarget)
if (currentCommonscatTarget == checkedCommonscatTarget):
# The current commonscat link is good
- pywikibot.output('Commonscat link at %s to Category:%s is ok'
- % (page.title(), currentCommonscatTarget))
+ pywikibot.output('Commonscat link at {} to Category:{} is ok'
+ .format(page.title(),
+ currentCommonscatTarget))
return True
elif checkedCommonscatTarget != '':
# We have a new Commonscat link, replace the old one
@@ -327,8 +328,8 @@
# TODO: if the commonsLink == '', should it be removed?
elif self.skipPage(page):
- pywikibot.output('Found a template in the skip list. Skipping %s'
- % page.title())
+ pywikibot.output('Found a template in the skip list. Skipping '
+ + page.title())
else:
commonscatLink = self.findCommonscatLink(page)
if (commonscatLink != ''):
@@ -404,9 +405,9 @@
possibleCommonscat)
if (checkedCommonscat != ''):
pywikibot.output(
- 'Found link for %s at [[%s:%s]] to %s.'
- % (page.title(), ipage.site.code,
- ipage.title(), checkedCommonscat))
+ 'Found link for {} at [[{}:{}]] to {}.'
+ .format(page.title(), ipage.site.code, ipage.title(),
+ checkedCommonscat))
return checkedCommonscat
except pywikibot.BadTitle:
# The interwiki was incorrect
@@ -442,7 +443,7 @@
commonscatLinktext, commonscatNote)
return None
- def checkCommonscatLink(self, name=""):
+ def checkCommonscatLink(self, name=''):
"""Return the name of a valid commons category.
If the page is a redirect this function tries to follow it.
@@ -477,9 +478,9 @@
return self.checkCommonscatLink(m.group('newcat2'))
else:
pywikibot.output(
- "getCommonscat: %s deleted by %s. Couldn't find "
- 'move target in "%s"'
- % (commonsPage, loguser, logcomment))
+ "getCommonscat: {} deleted by {}. Couldn't find "
+ 'move target in "{}"'
+ .format(commonsPage, loguser, logcomment))
return ''
return ''
elif commonsPage.isRedirectPage():
--
To view, visit https://gerrit.wikimedia.org/r/462764
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I303434ee78d2b0c4b04d95eabf43338d78973364
Gerrit-Change-Number: 462764
Gerrit-PatchSet: 2
Gerrit-Owner: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: D3r1ck01 <alangiderick(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)