jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/463512 )
Change subject: [cleanup] cleanup tests/[i18n_tests.py-isbn_tests.py] ......................................................................
[cleanup] cleanup tests/[i18n_tests.py-isbn_tests.py]
- use single quotes for string literals - remove preleading "u" fron strings - indentation to make sure code lines are less than 79 characters - use str.format(...) instead of modulo for type specifier arguments
Change-Id: If0d7074ad7d8ce65e903a26438a88ea8119fab9d --- M tests/i18n_tests.py M tests/interwiki_link_tests.py M tests/isbn_tests.py 3 files changed, 96 insertions(+), 88 deletions(-)
Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py index a68ddc6..0bad4ee 100644 --- a/tests/i18n_tests.py +++ b/tests/i18n_tests.py @@ -26,65 +26,65 @@
def setUp(self): """Set up test method.""" - self.msg_localized = {'en': u'test-localized EN', - 'nl': u'test-localized NL', - 'fy': u'test-localized FY'} - self.msg_semi_localized = {'en': u'test-semi-localized EN', - 'nl': u'test-semi-localized NL'} - self.msg_non_localized = {'en': u'test-non-localized EN'} - self.msg_no_english = {'ja': u'test-no-english JA'} + self.msg_localized = {'en': 'test-localized EN', + 'nl': 'test-localized NL', + 'fy': 'test-localized FY'} + self.msg_semi_localized = {'en': 'test-semi-localized EN', + 'nl': 'test-semi-localized NL'} + self.msg_non_localized = {'en': 'test-non-localized EN'} + self.msg_no_english = {'ja': 'test-no-english JA'} super(TestTranslate, self).setUp()
def testLocalized(self): """Test fully localized translations.""" self.assertEqual(i18n.translate('en', self.msg_localized, fallback=True), - u'test-localized EN') + 'test-localized EN') self.assertEqual(i18n.translate('nl', self.msg_localized, fallback=True), - u'test-localized NL') + 'test-localized NL') self.assertEqual(i18n.translate('fy', self.msg_localized, fallback=True), - u'test-localized FY') + 'test-localized FY')
def testSemiLocalized(self): """Test translate by fallback to an alternative language.""" self.assertEqual(i18n.translate('en', self.msg_semi_localized, fallback=True), - u'test-semi-localized EN') + 'test-semi-localized EN') self.assertEqual(i18n.translate('nl', self.msg_semi_localized, fallback=True), - u'test-semi-localized NL') + 'test-semi-localized NL') self.assertEqual(i18n.translate('fy', self.msg_semi_localized, fallback=True), - u'test-semi-localized NL') + 'test-semi-localized NL')
def testNonLocalized(self): """Test translate with missing localisation.""" self.assertEqual(i18n.translate('en', self.msg_non_localized, fallback=True), - u'test-non-localized EN') + 'test-non-localized EN') self.assertEqual(i18n.translate('fy', self.msg_non_localized, fallback=True), - u'test-non-localized EN') + 'test-non-localized EN') self.assertEqual(i18n.translate('nl', self.msg_non_localized, fallback=True), - u'test-non-localized EN') + 'test-non-localized EN') self.assertEqual(i18n.translate('ru', self.msg_non_localized, fallback=True), - u'test-non-localized EN') + 'test-non-localized EN')
def testNoEnglish(self): """Test translate with missing English text.""" self.assertEqual(i18n.translate('en', self.msg_no_english, fallback=True), - u'test-no-english JA') + 'test-no-english JA') self.assertEqual(i18n.translate('fy', self.msg_no_english, fallback=True), - u'test-no-english JA') + 'test-no-english JA') self.assertEqual(i18n.translate('nl', self.msg_no_english, fallback=True), - u'test-no-english JA') + 'test-no-english JA')
class UserInterfaceLangTestCase(TestCase): @@ -129,8 +129,8 @@ def setUpClass(cls): """Verify that the test translations are not empty.""" if not isinstance(cls.message_package, StringTypes): - raise TypeError('%s.message_package must be a package name' - % cls.__name__) + raise TypeError('{}.message_package must be a package name' + .format(cls.__name__)) # The call to set_messages_package below exists only to confirm # that the package exists and messages are available, so # that tests can be skipped if the i18n data doesnt exist. @@ -139,8 +139,8 @@ has_messages = i18n.messages_available() i18n._messages_package_name = cls.orig_messages_package_name if not has_messages: - raise unittest.SkipTest("i18n messages package '%s' not available." - % cls.message_package) + raise unittest.SkipTest("i18n messages package '{}' not available." + .format(cls.message_package)) super(TWNTestCaseBase, cls).setUpClass()
@@ -154,31 +154,31 @@ def testLocalized(self): """Test fully localized entry.""" self.assertEqual(i18n.twtranslate('en', 'test-localized'), - u'test-localized EN') + 'test-localized EN') self.assertEqual(i18n.twtranslate('nl', 'test-localized'), - u'test-localized NL') + 'test-localized NL') self.assertEqual(i18n.twtranslate('fy', 'test-localized'), - u'test-localized FY') + 'test-localized FY')
def testSemiLocalized(self): """Test translating with fallback to alternative language.""" self.assertEqual(i18n.twtranslate('en', 'test-semi-localized'), - u'test-semi-localized EN') + 'test-semi-localized EN') self.assertEqual(i18n.twtranslate('nl', 'test-semi-localized'), - u'test-semi-localized NL') + 'test-semi-localized NL') self.assertEqual(i18n.twtranslate('fy', 'test-semi-localized'), - u'test-semi-localized NL') + 'test-semi-localized NL')
def testNonLocalized(self): """Test translating non localized entries.""" self.assertEqual(i18n.twtranslate('en', 'test-non-localized'), - u'test-non-localized EN') + 'test-non-localized EN') self.assertEqual(i18n.twtranslate('fy', 'test-non-localized'), - u'test-non-localized EN') + 'test-non-localized EN') self.assertEqual(i18n.twtranslate('nl', 'test-non-localized'), - u'test-non-localized EN') + 'test-non-localized EN') self.assertEqual(i18n.twtranslate('ru', 'test-non-localized'), - u'test-non-localized EN') + 'test-non-localized EN')
def testNoEnglish(self): """Test translating into English with missing entry.""" @@ -197,95 +197,96 @@ """Use a number.""" self.assertEqual( i18n.twntranslate('de', 'test-plural', 0) % {'num': 0}, - u'Bot: Ändere 0 Seiten.') + 'Bot: Ändere 0 Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-plural', 1) % {'num': 1}, - u'Bot: Ändere 1 Seite.') + 'Bot: Ändere 1 Seite.') self.assertEqual( i18n.twntranslate('de', 'test-plural', 2) % {'num': 2}, - u'Bot: Ändere 2 Seiten.') + 'Bot: Ändere 2 Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-plural', 3) % {'num': 3}, - u'Bot: Ändere 3 Seiten.') + 'Bot: Ändere 3 Seiten.') self.assertEqual( i18n.twntranslate('en', 'test-plural', 0) % {'num': 'no'}, - u'Bot: Changing no pages.') + 'Bot: Changing no pages.') self.assertEqual( i18n.twntranslate('en', 'test-plural', 1) % {'num': 'one'}, - u'Bot: Changing one page.') + 'Bot: Changing one page.') self.assertEqual( i18n.twntranslate('en', 'test-plural', 2) % {'num': 'two'}, - u'Bot: Changing two pages.') + 'Bot: Changing two pages.') self.assertEqual( i18n.twntranslate('en', 'test-plural', 3) % {'num': 'three'}, - u'Bot: Changing three pages.') + 'Bot: Changing three pages.')
def testString(self): """Use a string.""" self.assertEqual( i18n.twntranslate('en', 'test-plural', '1') % {'num': 'one'}, - u'Bot: Changing one page.') + 'Bot: Changing one page.')
def testDict(self): """Use a dictionary.""" self.assertEqual( i18n.twntranslate('en', 'test-plural', {'num': 2}), - u'Bot: Changing 2 pages.') + 'Bot: Changing 2 pages.')
def testExtended(self): """Use additional format strings.""" self.assertEqual( - i18n.twntranslate('fr', 'test-plural', {'num': 1, 'descr': 'seulement'}), - u'Robot: Changer seulement une page.') + i18n.twntranslate('fr', 'test-plural', + {'num': 1, 'descr': 'seulement'}), + 'Robot: Changer seulement une page.')
def testExtendedOutside(self): """Use additional format strings also outside.""" self.assertEqual( i18n.twntranslate('fr', 'test-plural', 1) % {'descr': 'seulement'}, - u'Robot: Changer seulement une page.') + 'Robot: Changer seulement une page.')
def testMultiple(self): """Test using multiple plural entries.""" self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', 1) - % {'action': u'Ändere', 'line': u'eine'}, - u'Bot: Ändere eine Zeile von einer Seite.') + % {'action': 'Ändere', 'line': 'eine'}, + 'Bot: Ändere eine Zeile von einer Seite.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', 2) - % {'action': u'Ändere', 'line': u'zwei'}, + % {'action': 'Ändere', 'line': 'zwei'}, u'Bot: Ändere zwei Zeilen von mehreren Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', 3) - % {'action': u'Ändere', 'line': u'drei'}, - u'Bot: Ändere drei Zeilen von mehreren Seiten.') + % {'action': 'Ändere', 'line': 'drei'}, + 'Bot: Ändere drei Zeilen von mehreren Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', (1, 2, 2)) - % {'action': u'Ändere', 'line': u'eine'}, - u'Bot: Ändere eine Zeile von mehreren Seiten.') + % {'action': 'Ändere', 'line': 'eine'}, + 'Bot: Ändere eine Zeile von mehreren Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', [3, 1, 1]) - % {'action': u'Ändere', 'line': u'drei'}, - u'Bot: Ändere drei Zeilen von einer Seite.') + % {'action': 'Ändere', 'line': 'drei'}, + 'Bot: Ändere drei Zeilen von einer Seite.') self.assertEqual( - i18n.twntranslate('de', 'test-multiple-plurals', ["3", 1, 1]) - % {'action': u'Ändere', 'line': u'drei'}, - u'Bot: Ändere drei Zeilen von einer Seite.') + i18n.twntranslate('de', 'test-multiple-plurals', ['3', 1, 1]) + % {'action': 'Ändere', 'line': 'drei'}, + 'Bot: Ändere drei Zeilen von einer Seite.') self.assertEqual( - i18n.twntranslate('de', 'test-multiple-plurals', "321") - % {'action': u'Ändere', 'line': u'dreihunderteinundzwanzig'}, - u'Bot: Ändere dreihunderteinundzwanzig Zeilen von mehreren Seiten.') + i18n.twntranslate('de', 'test-multiple-plurals', '321') + % {'action': 'Ändere', 'line': 'dreihunderteinundzwanzig'}, + 'Bot: Ändere dreihunderteinundzwanzig Zeilen von mehreren Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', - {'action': u'Ändere', 'line': 1, 'page': 1}), - u'Bot: Ändere 1 Zeile von einer Seite.') + {'action': 'Ändere', 'line': 1, 'page': 1}), + 'Bot: Ändere 1 Zeile von einer Seite.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', - {'action': u'Ändere', 'line': 1, 'page': 2}), - u'Bot: Ändere 1 Zeile von mehreren Seiten.') + {'action': 'Ändere', 'line': 1, 'page': 2}), + 'Bot: Ändere 1 Zeile von mehreren Seiten.') self.assertEqual( i18n.twntranslate('de', 'test-multiple-plurals', - {'action': u'Ändere', 'line': "11", 'page': 2}), - u'Bot: Ändere 11 Zeilen von mehreren Seiten.') + {'action': 'Ändere', 'line': '11', 'page': 2}), + 'Bot: Ändere 11 Zeilen von mehreren Seiten.')
def testMultipleWrongParameterLength(self): """Test wrong parameter length.""" @@ -294,19 +295,19 @@ i18n.twntranslate('de', 'test-multiple-plurals', (1, 2))
with self.assertRaisesRegex(ValueError, err_msg): - i18n.twntranslate('de', 'test-multiple-plurals', ["321"]) + i18n.twntranslate('de', 'test-multiple-plurals', ['321'])
def testMultipleNonNumbers(self): """Test error handling for multiple non-numbers.""" with self.assertRaisesRegex( ValueError, r"invalid literal for int() with base 10: 'drei'" ): - i18n.twntranslate('de', 'test-multiple-plurals', ["drei", "1", 1]) + i18n.twntranslate('de', 'test-multiple-plurals', ['drei', '1', 1]) with self.assertRaisesRegex( ValueError, r"invalid literal for int() with base 10: 'elf'" ): i18n.twntranslate('de', 'test-multiple-plurals', - {'action': u'Ändere', 'line': "elf", 'page': 2}) + {'action': 'Ändere', 'line': 'elf', 'page': 2})
def testAllParametersExist(self): """Test that all parameters are required when using a dict.""" @@ -329,11 +330,13 @@ assert 'co' not in plural.plural_rules assert plural.plural_rules['fr']['plural'](0) is False self.assertEqual( - i18n.twntranslate('co', 'test-plural', {'num': 0, 'descr': 'seulement'}), - u'Robot: Changer seulement une page.') + i18n.twntranslate('co', 'test-plural', + {'num': 0, 'descr': 'seulement'}), + 'Robot: Changer seulement une page.') self.assertEqual( - i18n.twntranslate('co', 'test-plural', {'num': 1, 'descr': 'seulement'}), - u'Robot: Changer seulement une page.') + i18n.twntranslate('co', 'test-plural', + {'num': 1, 'descr': 'seulement'}), + 'Robot: Changer seulement une page.')
class ScriptMessagesTestCase(TWNTestCaseBase, AutoDeprecationTestCase): @@ -372,8 +375,8 @@
if cls.code in i18n.twget_keys(cls.message): raise unittest.SkipTest( - '%s has a translation for %s' - % (cls.code, cls.message)) + '{} has a translation for {}' + .format(cls.code, cls.message))
def test_pagegen_i18n_input(self): """Test i18n.input fallback via pwb.""" @@ -426,13 +429,16 @@ def test_standard(self): """Test default usage using a dict and no specific plurals.""" self.assertEqual( - i18n._extract_plural('en', '{{PLURAL:foo|one|other}}', {'foo': 42}), + i18n._extract_plural('en', '{{PLURAL:foo|one|other}}', + {'foo': 42}), 'other') self.assertEqual( - i18n._extract_plural('en', '{{PLURAL:foo|one|other}}', {'foo': 1}), + i18n._extract_plural('en', '{{PLURAL:foo|one|other}}', + {'foo': 1}), 'one') self.assertEqual( - i18n._extract_plural('en', '{{PLURAL:foo|one|other}}', {'foo': 0}), + i18n._extract_plural('en', '{{PLURAL:foo|one|other}}', + {'foo': 0}), 'other')
def test_empty_fields(self): diff --git a/tests/interwiki_link_tests.py b/tests/interwiki_link_tests.py index acd2a49..50b70ef 100644 --- a/tests/interwiki_link_tests.py +++ b/tests/interwiki_link_tests.py @@ -84,8 +84,8 @@ link = Link('de:translatewiki:Main Page', self.get_site('wp')) self.assertRaisesRegex( InvalidTitle, - "de:translatewiki:Main Page links to a non local site i18n:i18n " - "via an interwiki link to wikipedia:de", + 'de:translatewiki:Main Page links to a non local site i18n:i18n ' + 'via an interwiki link to wikipedia:de', link.parse)
diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py index 82c01ce..c2a409e 100644 --- a/tests/isbn_tests.py +++ b/tests/isbn_tests.py @@ -85,7 +85,8 @@
def test_ignore_invalid_isbn(self): """Test fixing ISBN numbers with an invalid ISBN.""" - cc = CosmeticChangesToolkit(self.site, namespace=0, ignore=CANCEL_MATCH) + cc = CosmeticChangesToolkit(self.site, namespace=0, + ignore=CANCEL_MATCH)
text = cc.fix_ISBN(' ISBN 0975229LOL ISBN 9780975229804 ') self.assertEqual(text, ' ISBN 0975229LOL ISBN 978-0-9752298-0-4 ') @@ -230,7 +231,8 @@ TestIsbnBot.newtext = newtext
-class TestIsbnWikibaseBot(ScriptMainTestCase, WikibaseTestCase, TWNBotTestCase): +class TestIsbnWikibaseBot(ScriptMainTestCase, WikibaseTestCase, + TWNBotTestCase):
"""Test isbnbot on Wikibase site with non-write patching."""
@@ -257,11 +259,11 @@ claim.getTarget() == '097522980x'): return raise unittest.SkipTest( - u'%s: "ISBN-10" property was not found in ' - u'"IsbnWikibaseBotUnitTest" item page' % cls.__name__) + '{}: "ISBN-10" property was not found in ' + '"IsbnWikibaseBotUnitTest" item page'.format(cls.__name__)) raise unittest.SkipTest( - u'%s: "IsbnWikibaseBotUnitTest" item page was not found' - % cls.__name__) + '{}: "IsbnWikibaseBotUnitTest" item page was not found' + .format(cls.__name__))
def setUp(self): """Patch Claim.setTarget and ItemPage.editEntity which write."""
pywikibot-commits@lists.wikimedia.org