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