jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/487464 )
Change subject: [tests] Enable hacking rules H203,H204,H205 ......................................................................
[tests] Enable hacking rules H203,H204,H205
- [H203] Use assertIs(Not)None to check for None - [H204] Use assert(Not)Equal to check for equality - [H205] Use assert(Greater|Less)(Equal) for comparison
Change-Id: I4d81f8809807cd736c6e288004ed7e47bb7a45f6 --- M tests/api_tests.py M tests/category_bot_tests.py M tests/category_tests.py M tests/deprecation_tests.py M tests/dry_site_tests.py M tests/edit_tests.py M tests/family_tests.py M tests/logentry_tests.py M tests/mediawikiversion_tests.py M tests/namespace_tests.py M tests/page_tests.py M tests/proofreadpage_tests.py M tests/redirect_bot_tests.py M tests/site_tests.py M tests/timestripper_tests.py M tox.ini 16 files changed, 73 insertions(+), 73 deletions(-)
Approvals: Dalba: Looks good to me, but someone else must approve Mpaa: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/api_tests.py b/tests/api_tests.py index d075dde..13f56e4 100644 --- a/tests/api_tests.py +++ b/tests/api_tests.py @@ -660,7 +660,7 @@
def test_initial_limit(self): """Test the default limit.""" - self.assertEqual(self.gen.limit, None) # limit is initally None + self.assertIsNone(self.gen.limit) # limit is initally None
def test_set_limit_as_number(self): """Test setting the limit using an int.""" diff --git a/tests/category_bot_tests.py b/tests/category_bot_tests.py index da3d34b..601ad92 100644 --- a/tests/category_bot_tests.py +++ b/tests/category_bot_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the category bot script.""" # -# (C) Pywikibot team, 2015-2018 +# (C) Pywikibot team, 2015-2019 # # Distributed under the terms of the MIT license. # @@ -85,13 +85,13 @@ bot = CategoryPreprocess() bot.site = self.site new_page = bot.determine_type_target(page) - self.assertEqual(new_page, None) + self.assertIsNone(new_page)
page = pywikibot.Page(self.site, 'Template:Baz') bot = CategoryPreprocess() bot.site = self.site new_page = bot.determine_type_target(page) - self.assertEqual(new_page, None) + self.assertIsNone(new_page)
def test_determine_template_target(self): """Test determining template target.""" diff --git a/tests/category_tests.py b/tests/category_tests.py index 413f8b7..2e38ff7 100644 --- a/tests/category_tests.py +++ b/tests/category_tests.py @@ -54,10 +54,10 @@ site = self.get_site() cat = pywikibot.Category(site, 'Category:Female Wikipedians') categoryinfo = cat.categoryinfo - self.assertTrue(categoryinfo['files'] >= 0) - self.assertTrue(categoryinfo['pages'] >= 0) - self.assertTrue(categoryinfo['size'] > 0) - self.assertTrue(categoryinfo['subcats'] > 0) + self.assertGreaterEqual(categoryinfo['files'], 0) + self.assertGreaterEqual(categoryinfo['pages'], 0) + self.assertGreater(categoryinfo['size'], 0) + self.assertGreater(categoryinfo['subcats'], 0) members_sum = (categoryinfo['files'] + categoryinfo['pages'] + categoryinfo['subcats']) self.assertEqual(members_sum, categoryinfo['size']) @@ -65,7 +65,7 @@ cat_files = pywikibot.Category(site, 'Category:Files lacking an author') categoryinfo2 = cat_files.categoryinfo - self.assertTrue(categoryinfo2['files'] > 0) + self.assertGreater(categoryinfo2['files'], 0)
def test_members(self): """Test the members method.""" @@ -219,7 +219,7 @@ cat = pywikibot.Category(site, 'Category:Foo#bar') self.assertEqual(cat.section(), 'bar') cat2 = pywikibot.Category(site, 'Category:Foo') - self.assertEqual(cat2.section(), None) + self.assertIsNone(cat2.section())
def test_aslink(self): """Test the title method with as_link=True.""" diff --git a/tests/deprecation_tests.py b/tests/deprecation_tests.py index b1b565f..212cad8 100644 --- a/tests/deprecation_tests.py +++ b/tests/deprecation_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for deprecation tools.""" # -# (C) Pywikibot team, 2014-2018 +# (C) Pywikibot team, 2014-2019 # # Distributed under the terms of the MIT license. # @@ -269,7 +269,7 @@ def test_deprecated_function_zero_arg(self): """Test @deprecated with functions, with zero arguments.""" rv = deprecated_func() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertOneDeprecationParts(__name__ + '.deprecated_func')
def test_deprecated_function(self): @@ -322,7 +322,7 @@ def test_deprecated_function_bad_args(self): """Test @deprecated function with bad arguments.""" rv = deprecated_func_bad_args(None) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertOneDeprecationParts(__name__ + '.deprecated_func_bad_args')
rv = deprecated_func_bad_args('a') @@ -343,8 +343,8 @@ f = DeprecatedMethodClass()
rv = f.instance_method() - self.assertEqual(rv, None) - self.assertEqual(f.foo, None) + self.assertIsNone(rv) + self.assertIsNone(f.foo) self.assertOneDeprecationParts( __name__ + '.DeprecatedMethodClass.instance_method')
@@ -365,15 +365,15 @@ f = DeprecatedMethodClass()
rv = f.instance_method2() - self.assertEqual(rv, None) - self.assertEqual(f.foo, None) + self.assertIsNone(rv) + self.assertIsNone(f.foo) self.assertOneDeprecationParts( __name__ + '.DeprecatedMethodClass.instance_method2')
def test_deprecated_class_method(self): """Test @deprecated with class methods.""" rv = DeprecatedMethodClass.class_method() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertOneDeprecationParts( __name__ + '.DeprecatedMethodClass.class_method')
@@ -390,7 +390,7 @@ def test_deprecated_static_method_zero_args(self): """Test @deprecated with static methods, with zero arguments.""" rv = DeprecatedMethodClass.static_method() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertOneDeprecationParts( __name__ + '.DeprecatedMethodClass.static_method')
@@ -413,7 +413,7 @@ self.assertOneDeprecationParts(__name__ + '.DeprecatedClassNoInit')
df = DeprecatedClass() - self.assertEqual(df.foo, None) + self.assertIsNone(df.foo) self.assertOneDeprecationParts(__name__ + '.DeprecatedClass')
def test_deprecate_class(self): @@ -427,7 +427,7 @@ def tests(func): """Test function.""" rv = func() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertNoDeprecation()
rv = func('a') @@ -458,7 +458,7 @@ def test_deprecate_and_remove_function_args(self): """Test @deprecated and removed function argument.""" rv = deprecated_func_arg3() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertNoDeprecation()
rv = deprecated_func_arg3(2) @@ -484,11 +484,11 @@ def test_function_remove_last_args(self): """Test @remove_last_args on functions.""" rv = deprecated_all() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertNoDeprecation()
rv = deprecated_all(foo=42) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of {}.deprecated_all are " "deprecated. The value(s) provided for 'foo' have been " @@ -497,7 +497,7 @@ self._reset_messages()
rv = deprecated_all(42) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of {}.deprecated_all are " "deprecated. The value(s) provided for 'foo' have been " @@ -506,7 +506,7 @@ self._reset_messages()
rv = deprecated_all(foo=42, bar=47) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of {}.deprecated_all are " "deprecated. The value(s) provided for 'foo', 'bar' have been " @@ -515,7 +515,7 @@ self._reset_messages()
rv = deprecated_all(42, 47) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of {}.deprecated_all are " "deprecated. The value(s) provided for 'foo', 'bar' have been " @@ -545,11 +545,11 @@ f = DeprecatedMethodClass()
rv = f.deprecated_all() - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertNoDeprecation()
rv = f.deprecated_all(foo=42) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of " '{}.DeprecatedMethodClass.deprecated_all are deprecated. ' @@ -559,7 +559,7 @@ self._reset_messages()
rv = f.deprecated_all(42) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of " '{}.DeprecatedMethodClass.deprecated_all are deprecated. ' @@ -569,7 +569,7 @@ self._reset_messages()
rv = f.deprecated_all(foo=42, bar=47) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of " '{}.DeprecatedMethodClass.deprecated_all are deprecated. The ' @@ -579,7 +579,7 @@ self._reset_messages()
rv = f.deprecated_all(42, 47) - self.assertEqual(rv, None) + self.assertIsNone(rv) self.assertDeprecation( "The trailing arguments ('foo', 'bar') of " '{}.DeprecatedMethodClass.deprecated_all are deprecated. The ' @@ -657,8 +657,8 @@ f = DeprecatedMethodClass()
rv = f.deprecated_instance_method_arg() - self.assertEqual(rv, None) - self.assertEqual(f.foo, None) + self.assertIsNone(rv) + self.assertIsNone(f.foo) self.assertNoDeprecation()
def test_deprecated_instance_method_arg(self): diff --git a/tests/dry_site_tests.py b/tests/dry_site_tests.py index f9157d4..bc240e4 100644 --- a/tests/dry_site_tests.py +++ b/tests/dry_site_tests.py @@ -148,7 +148,7 @@
def testMockInTest(self): """Test that setUp and login work.""" - self.assertEqual(self._logged_in_as, None) + self.assertIsNone(self._logged_in_as) self.login(True) self.assertEqual(self._logged_in_as, 'sysop')
diff --git a/tests/edit_tests.py b/tests/edit_tests.py index bf638a5..715ecd6 100644 --- a/tests/edit_tests.py +++ b/tests/edit_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for editing pages.""" # -# (C) Pywikibot team, 2015-2018 +# (C) Pywikibot team, 2015-2019 # # Distributed under the terms of the MIT license. # @@ -68,7 +68,7 @@ self.assertFalse(hasattr(p, '_text')) p = pywikibot.Page(self.site, 'User:John Vandenberg/appendtext test') self.assertTrue(p.text.endswith(ts)) - self.assertTrue(p.text != ts) + self.assertNotEqual(p.text, ts)
class TestSiteMergeHistory(TestCase): diff --git a/tests/family_tests.py b/tests/family_tests.py index 1538693..eee320f 100644 --- a/tests/family_tests.py +++ b/tests/family_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the family module.""" # -# (C) Pywikibot team, 2014-2018 +# (C) Pywikibot team, 2014-2019 # # Distributed under the terms of the MIT license. # @@ -89,14 +89,14 @@ family = Family.load('wikipedia') other = 'wikipedia' self.assertEqual(family, other) - self.assertFalse(family != other) + self.assertFalse(family != other) # noqa: H204
def test_ne_family_with_string_repr_different_family(self): """Test that Family and string with different name are not equal.""" family = Family.load('wikipedia') other = 'wikisource' self.assertNotEqual(family, other) - self.assertFalse(family == other) + self.assertFalse(family == other) # noqa: H204
def test_eq_family_with_string_repr_not_existing_family(self): """Test that Family and string with different name are not equal.""" @@ -115,9 +115,9 @@ # redirected code (see site tests test_alias_code_site) self.assertEqual(family.obsolete['dk'], 'da') # closed/locked site (see site tests test_locked_site) - self.assertEqual(family.obsolete['mh'], None) + self.assertIsNone(family.obsolete['mh']) # offline site (see site tests test_removed_site) - self.assertEqual(family.obsolete['ru-sib'], None) + self.assertIsNone(family.obsolete['ru-sib'])
def test_get_obsolete_test(self): """Test WikimediaFamily default obsolete.""" diff --git a/tests/logentry_tests.py b/tests/logentry_tests.py index 348701a..39fb490 100644 --- a/tests/logentry_tests.py +++ b/tests/logentry_tests.py @@ -251,7 +251,7 @@ le4 = next(gen1) le5 = next(gen2) self.assertEqual(le1, le2) - self.assertFalse(le1 != le2) # __ne__ test + self.assertFalse(le1 != le2) # noqa: H204 self.assertNotEqual(le1, le3) self.assertNotEqual(le1, site) self.assertIsInstance(le4, OtherLogEntry) diff --git a/tests/mediawikiversion_tests.py b/tests/mediawikiversion_tests.py index 495e5ba..fdab731 100644 --- a/tests/mediawikiversion_tests.py +++ b/tests/mediawikiversion_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the tools.MediaWikiVersion class.""" # -# (C) Pywikibot team, 2008-2018 +# (C) Pywikibot team, 2008-2019 # # Distributed under the terms of the MIT license. # @@ -30,7 +30,6 @@ def test_normal_versions(self): """Test comparison between release versions.""" self.assertGreater(self._make('1.23'), self._make('1.22.0')) - self.assertTrue(self._make('1.23') == self._make('1.23')) self.assertEqual(self._make('1.23'), self._make('1.23'))
def test_wmf_versions(self): diff --git a/tests/namespace_tests.py b/tests/namespace_tests.py index 21c1ab8..08f9c86 100644 --- a/tests/namespace_tests.py +++ b/tests/namespace_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the Namespace class.""" # -# (C) Pywikibot team, 2014-2018 +# (C) Pywikibot team, 2014-2019 # # Distributed under the terms of the MIT license. # @@ -141,9 +141,9 @@
self.assertEqual(a, 0) self.assertEqual(a, '') - self.assertFalse(a < 0) - self.assertFalse(a > 0) - self.assertNotEqual(a, None) + self.assertFalse(a < 0) # noqa: H205 + self.assertFalse(a > 0) # noqa: H205 + self.assertNotEqual(a, None) # noqa: H203
self.assertGreater(a, -1)
@@ -170,8 +170,8 @@ self.assertEqual(x, 'image') self.assertEqual(x, 'Image')
- self.assertFalse(x < 6) - self.assertFalse(x > 6) + self.assertFalse(x < 6) # noqa: H205 + self.assertFalse(x > 6) # noqa: H205
self.assertEqual(y, 'ملف')
diff --git a/tests/page_tests.py b/tests/page_tests.py index 4b99130..0dbd553 100644 --- a/tests/page_tests.py +++ b/tests/page_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the page module.""" # -# (C) Pywikibot team, 2008-2018 +# (C) Pywikibot team, 2008-2019 # # Distributed under the terms of the MIT license. # @@ -410,7 +410,7 @@ p1 = pywikibot.Page(site, 'Help:Test page#Testing') p2 = pywikibot.Page(site, 'File:Jean-Léon Gérôme 003.jpg') self.assertEqual(p1.section(), 'Testing') - self.assertEqual(p2.section(), None) + self.assertIsNone(p2.section())
def testIsTalkPage(self): """Test isTalkPage() method.""" @@ -419,10 +419,10 @@ p2 = pywikibot.Page(site, 'Talk:First page') p3 = pywikibot.Page(site, 'User:Second page') p4 = pywikibot.Page(site, 'User talk:Second page') - self.assertEqual(p1.isTalkPage(), False) - self.assertEqual(p2.isTalkPage(), True) - self.assertEqual(p3.isTalkPage(), False) - self.assertEqual(p4.isTalkPage(), True) + self.assertFalse(p1.isTalkPage()) + self.assertTrue(p2.isTalkPage()) + self.assertFalse(p3.isTalkPage()) + self.assertTrue(p4.isTalkPage())
def testIsCategory(self): """Test is_categorypage method.""" diff --git a/tests/proofreadpage_tests.py b/tests/proofreadpage_tests.py index ee0b134..e35d3a5 100644 --- a/tests/proofreadpage_tests.py +++ b/tests/proofreadpage_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the proofreadpage module.""" # -# (C) Pywikibot team, 2015-2018 +# (C) Pywikibot team, 2015-2019 # # Distributed under the terms of the MIT license. # @@ -450,7 +450,7 @@
# Page without Index. page = ProofreadPage(self.site, self.existing_unlinked['title']) - self.assertIs(page.index, None) + self.assertIsNone(page.index) self.assertEqual(page._index, (None, []))
diff --git a/tests/redirect_bot_tests.py b/tests/redirect_bot_tests.py index 9072205..6135408 100644 --- a/tests/redirect_bot_tests.py +++ b/tests/redirect_bot_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for the redirect.py script.""" # -# (C) Pywikibot team, 2017-2018 +# (C) Pywikibot team, 2017-2019 # # Distributed under the terms of the MIT license. # @@ -42,7 +42,7 @@ with patch.object(pywikibot, 'warning') as w: bot = RedirectRobot('broken', delete=True) w.assert_called_with('No speedy deletion template available.') - self.assertEqual(bot.sdtemplate, None) + self.assertIsNone(bot.sdtemplate)
def test_with_delete_and_non_existing_sdtemplate(self): """Test with delete and non-exisitng sdtemplate.""" @@ -51,7 +51,7 @@ with patch.object(pywikibot, 'warning') as w: bot = RedirectRobot('broken', **options) w.assert_called_with('No speedy deletion template "n" available.') - self.assertEqual(bot.sdtemplate, None) + self.assertIsNone(bot.sdtemplate)
if __name__ == '__main__': # pragma: no cover diff --git a/tests/site_tests.py b/tests/site_tests.py index 6f6dc77..2184dec 100644 --- a/tests/site_tests.py +++ b/tests/site_tests.py @@ -1939,7 +1939,7 @@ 'move': 'autoconfirmed'}, page=p1, reason='Pywikibot unit test') - self.assertEqual(r, None) + self.assertIsNone(r) self.assertEqual(site.page_restrictions(page=p1), {'edit': ('sysop', 'infinity'), 'move': ('autoconfirmed', 'infinity')}) @@ -1968,7 +1968,7 @@ 'move': 'autoconfirmed'}, page=p1, reason='Pywikibot unit test') - self.assertEqual(r, None) + self.assertIsNone(r) self.assertEqual(site.page_restrictions(page=p1), {'edit': ('sysop', 'infinity'), 'move': ('autoconfirmed', 'infinity')}) @@ -2024,7 +2024,7 @@ site.deletepage(p, reason='pywikibot unit tests') site.undelete_page(p, 'pywikibot unit tests') revs = list(p.revisions()) - self.assertTrue(len(revs) > 2) + self.assertGreater(len(revs), 2)
class TestUsernameInUsers(DefaultSiteTestCase): diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py index f1aafbf..1e62b24 100644 --- a/tests/timestripper_tests.py +++ b/tests/timestripper_tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """Tests for archivebot.py/Timestripper.""" # -# (C) Pywikibot team, 2014-2018 +# (C) Pywikibot team, 2014-2019 # # Distributed under the terms of the MIT license. # @@ -95,8 +95,8 @@ txt_hour_in_range = '7 février 2010 à 23:00 (CET)' txt_hour_out_of_range = '7 février 2010 à 24:00 (CET)'
- self.assertNotEqual(self.ts.timestripper(txt_hour_in_range), None) - self.assertEqual(self.ts.timestripper(txt_hour_out_of_range), None) + self.assertIsNotNone(self.ts.timestripper(txt_hour_in_range)) + self.assertIsNone(self.ts.timestripper(txt_hour_out_of_range))
class TestTimeStripperWithDigitsAsMonths(TestTimeStripperCase): @@ -264,13 +264,13 @@ else: txt_no_match = '3 March 2011 19:48 (UTC) 7 March 2010 19:48 (UTC)'
- self.assertEqual(self.ts.timestripper(txt_no_match), None) + self.assertIsNone(self.ts.timestripper(txt_no_match))
if 'nomatch1' not in self.sites[key]: return
txt_no_match = self.sites[key]['nomatch1'] - self.assertEqual(self.ts.timestripper(txt_no_match), None) + self.assertIsNone(self.ts.timestripper(txt_no_match))
class TestTimeStripperTreatSpecialText(TestTimeStripperCase): @@ -354,7 +354,7 @@
txt_match = ('{}[http://example.com Here is long enough text]{}' .format(self.date[:9], self.date[9:])) - self.assertEqual(ts(txt_match), None) + self.assertIsNone(ts(txt_match))
def test_timestripper_match_wikilink_with_date(self): """Test that dates in wikilinks are correctly matched.""" @@ -378,7 +378,7 @@
txt_match = ('{}[[Here is long enough text]]{}' .format(self.date[:9], self.date[9:])) - self.assertEqual(ts(txt_match), None) + self.assertIsNone(ts(txt_match))
txt_match = self.date[:9] + '[[foo]]' + self.date[9:] self.assertEqual(ts(txt_match), self.expected_date) diff --git a/tox.ini b/tox.ini index 7ed4c0b..9c5e653 100644 --- a/tox.ini +++ b/tox.ini @@ -115,9 +115,9 @@ # FI5: __future__ import "x" present # H101: TODO format # H236: Mandatory use of six for Python 2 & 3 metaclass support +# H301: Do not import more than one module per line; Pywikibot uses H306 (Alphabetically order your imports by the full module path) # H404: docstring multiline start # H405: docstring summary line -# H301: Do not import more than one module per line; Pywikibot uses H306 (Alphabetically order your imports by the full module path) # P101: format string does contain unindexed parameters # P102: docstring does contain unindexed parameters # P103: other string does contain unindexed parameters @@ -139,6 +139,7 @@ # D412: No blank lines allowed between a section header and its content
ignore = D105,D211,D401,D413,D412,FI12,FI13,FI15,FI16,FI17,FI5,H101,H236,H301,H404,H405,H903,P101,P102,P103,W503,W504 +enable-extensions = H203,H204,H205 exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*,scripts/userscripts/* min-version = 2.7 accept-encodings = utf-8
pywikibot-commits@lists.wikimedia.org