jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/837671 )
Change subject: [tests] Remove some code parts from coverage ......................................................................
[tests] Remove some code parts from coverage
Also improve some tests.
Change-Id: I6bb8a2b346e9dc282c59d4776a0d51b0684f6e33 --- M make_dist.py M pwb.py M tests/bot_tests.py M tests/cosmetic_changes_tests.py M tests/i18n_tests.py M tests/pagegenerators_tests.py M tests/siteinfo_tests.py M tests/textlib_tests.py M tests/timestripper_tests.py M tests/ui_tests.py M tests/wikibase_tests.py 11 files changed, 41 insertions(+), 37 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/make_dist.py b/make_dist.py index 116e656..cb5c11a 100644 --- a/make_dist.py +++ b/make_dist.py @@ -112,7 +112,7 @@ :return: Return whether dist is to be installed locally or to be uploaded """ - if '-help' in sys.argv: + if '-help' in sys.argv: # pragma: no cover info(__doc__) info(setup.__doc__) sys.exit() diff --git a/pwb.py b/pwb.py index 4bf8253..b1694de 100755 --- a/pwb.py +++ b/pwb.py @@ -79,12 +79,12 @@ 'misconfigured.\n'.format(wikibot_version, scripts_version))
# calculate previous minor release - if wikibot_version.minor > 0: + if wikibot_version.minor > 0: # pragma: no cover prev_wikibot = Version('{v.major}.{}.{v.micro}' .format(wikibot_version.minor - 1, v=wikibot_version))
- if scripts_version.release < prev_wikibot.release: # pragma: no cover + if scripts_version.release < prev_wikibot.release: print('WARNING: Scripts package version {} is behind legacy ' 'Pywikibot version {} and current version {}\nYour scripts ' 'may need an update or be misconfigured.\n' @@ -138,7 +138,7 @@
# set environment values old_env = os.environ.copy() - for key, value in environ: + for key, value in environ: # pragma: no cover os.environ[key] = value
sys.argv = [filename] + args @@ -162,7 +162,7 @@ # end of snippet from coverage
# Restore environment values - for key, value in environ: + for key, value in environ: # pragma: no cover if key in old_env: os.environ[key] = old_env[key] else: diff --git a/tests/bot_tests.py b/tests/bot_tests.py index 8b51092..0d11ca5 100755 --- a/tests/bot_tests.py +++ b/tests/bot_tests.py @@ -93,7 +93,7 @@ # When an AssertionError happened we shouldn't do these # assertions as they are invalid anyway and hide the actual # failed assertion - return + return # pragma: no cover self.assertEqual(self.bot.counter['read'], treated) self.assertEqual(self.bot.counter['write'], written) if exception: diff --git a/tests/cosmetic_changes_tests.py b/tests/cosmetic_changes_tests.py index bd85465..6d38f91 100755 --- a/tests/cosmetic_changes_tests.py +++ b/tests/cosmetic_changes_tests.py @@ -395,14 +395,14 @@ '==2<!--\n-->==\nt', self.cct.removeEmptySections('==1==\n==2<!--\n-->==\nt'))
- def test_translateAndCapitalizeNamespaces(self): + def test_translate_and_capitalize_namespaces(self): """Test translateAndCapitalizeNamespaces method.""" self.assertEqual( '[[Wikipedia:Test]], [[Wikipedia:Test]], [[Datei:Test]]', self.cct.translateAndCapitalizeNamespaces( '[[Project:Test]], [[wikipedia:Test]], [[Image:Test]]'))
- def test_translateMagicWords(self): + def test_translate_magic_words(self): """Test translateMagicWords method.""" self.assertEqual( '[[File:Foo.bar|mini]]', @@ -471,23 +471,23 @@ self.cct.cleanUpLinks('[[Sand|sand]]box'))
@unittest.expectedFailure - def test_cleanUpLinks(self): - """ - Test cleanUpLinks method. + def test_cleanup_links(self): + """Test cleanUpLinks method.
This method fails for the given samples from library. Either the method has to be changed or the examples must be fixed. """ - self.assertEqual('text [[title]] text', - self.cct.cleanUpLinks('text[[ title ]]text')) - self.assertEqual('text [[title|name]] text', - self.cct.cleanUpLinks('text[[ title | name ]]text')) - self.assertEqual('text[[title|name]]text', - self.cct.cleanUpLinks('text[[ title |name]]text')) - self.assertEqual('text [[title|name]]text', - self.cct.cleanUpLinks('text[[title| name]]text')) + tests = [ + ('text [[title]] text', 'text[[ title ]]text'), + ('text [[title|name]] text', 'text[[ title | name ]]text'), + ('text[[title|name]]text', 'text[[ title |name]]text'), + ('text [[title|name]]text', 'text[[title| name]]text'), + ] + for result, text in tests: + with self.subTest(text=text): + self.assertEqual(self.cct.cleanUpLinks(text), result)
- def test_replaceDeprecatedTemplates(self): + def test_replace_deprecated_templates(self): """Test replaceDeprecatedTemplates method.""" self.assertEqual('{{Belege fehlen}}', self.cct.replaceDeprecatedTemplates('{{Belege}}')) @@ -503,13 +503,13 @@ family = 'wikipedia' code = 'fa'
- def test_fixArabicLetters_comma(self): + def test_fix_arabic_letters_comma(self): """Test fixArabicLetters comma replacements.""" self.assertEqual(self.cct.fixArabicLetters(','), '،') self.assertEqual(self.cct.fixArabicLetters('A,b,ا,۴,'), 'A,b،ا،۴،')
- def test_fixArabicLetters_comma_skip(self): + def test_fix_arabic_letters_comma_skip(self): """Test fixArabicLetters Latin comma not replaced.""" self.assertEqual(self.cct.fixArabicLetters('a", b'), 'a", b') self.assertEqual(self.cct.fixArabicLetters('a, "b'), 'a, "b') @@ -532,7 +532,7 @@ self.assertEqual(self.cct.fixArabicLetters('a", ۴'), 'a", ۴') self.assertEqual(self.cct.fixArabicLetters(' , '), ' , ')
- def test_fixArabicLetters_letters(self): + def test_fix_arabic_letters_letters(self): """Test fixArabicLetters letter replacements.""" self.assertEqual(self.cct.fixArabicLetters('ك'), 'ک') diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py index 9e21ed3..bf81f14 100755 --- a/tests/i18n_tests.py +++ b/tests/i18n_tests.py @@ -238,7 +238,7 @@ """Verify that the test translations are not empty.""" if not isinstance(cls.message_package, str): raise TypeError('{}.message_package must be a package name' - .format(cls.__name__)) + .format(cls.__name__)) # pragma: no cover # 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 doesn't exist. diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py index 1545b5f..6c2b890 100755 --- a/tests/pagegenerators_tests.py +++ b/tests/pagegenerators_tests.py @@ -1701,7 +1701,8 @@ with self.assertRaises(ValueError): for _ in pagegenerators.UnconnectedPageGenerator(self.site, total=5): - raise AssertionError("this shouldn't be reached") + raise AssertionError( + "this shouldn't be reached") # pragma: no cover
class TestLinksearchPageGenerator(TestCase): diff --git a/tests/siteinfo_tests.py b/tests/siteinfo_tests.py index 0a3c189..76f6031 100755 --- a/tests/siteinfo_tests.py +++ b/tests/siteinfo_tests.py @@ -72,7 +72,7 @@ def test_no_cache(self): """Test siteinfo caching can be disabled.""" if 'fileextensions' in self.site.siteinfo._cache: - del self.site.siteinfo._cache['fileextensions'] + del self.site.siteinfo._cache['fileextensions'] # pragma: no cover self.site.siteinfo.get('fileextensions', cache=False) self.assertFalse(self.site.siteinfo.is_cached('fileextensions'))
diff --git a/tests/textlib_tests.py b/tests/textlib_tests.py index c92e84d..86c494c 100755 --- a/tests/textlib_tests.py +++ b/tests/textlib_tests.py @@ -895,14 +895,16 @@ # These tests require to get the actual part which is before the title # (interwiki and namespace prefixes) which could be then compared # case insensitive. - self.assertEqual( - textlib.replace_links('[[Image:Foobar]]', - ('File:Foobar', 'File:Foo'), self.wp_site), - '[[File:Foo|Image:Foobar]]') - self.assertEqual( - textlib.replace_links('[[en:File:Foobar]]', - ('File:Foobar', 'File:Foo'), self.wp_site), - '[[File:Foo|en:File:Foobar]]') + tests = [ + ('[[Image:Foobar]]', '[[File:Foo|Image:Foobar]]'), + ('[[en:File:Foobar]]', '[[File:Foo|en:File:Foobar]]'), + ] + for link, result in tests: + with self.subTest(link=link): + self.assertEqual( + textlib.replace_links( + link, ('File:Foobar', 'File:Foo'), self.wp_site), + result)
def test_linktrails(self): """Test that the linktrails are used or applied.""" diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py index 65bb9a8..73bd011 100755 --- a/tests/timestripper_tests.py +++ b/tests/timestripper_tests.py @@ -244,7 +244,7 @@ self.assertEqual(self.ts.timestripper(txt_match), res)
if 'match3' not in self.sites[key]: - return + return # pragma: no cover
txt_match = self.sites[key]['match3']
diff --git a/tests/ui_tests.py b/tests/ui_tests.py index 8fecffe..ff9130b 100755 --- a/tests/ui_tests.py +++ b/tests/ui_tests.py @@ -403,7 +403,8 @@
def _encounter_color(self, color, target_stream): """Patched encounter_color method.""" - raise AssertionError('This method should not be invoked') + raise AssertionError( + 'This method should not be invoked') # pragma: no cover
def test_no_color(self): """Test a string without any colors.""" diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index f9ec66a..8f1f13f 100755 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -42,7 +42,7 @@ for page in gen: if not page.properties().get('wikibase_item'): return page - return None + return None # pragma: no cover
class WbRepresentationTestCase(WikidataTestCase):
pywikibot-commits@lists.wikimedia.org