jenkins-bot has submitted this change and it was merged.
Change subject: Enable hacking rule H202
......................................................................
Enable hacking rule H202
Hacking rule H202 prevents tests using self.assertRaises
with only 'Exception' being detected. It requires tests
to switch to using assertRaisesRegexp or use a more
specific Exception subclass.
Change-Id: I667d7ed3aa447412d99b5a503d09394b7c09a02d
---
M tests/isbn_tests.py
M tests/weblinkchecker_tests.py
M tox.ini
3 files changed, 27 insertions(+), 7 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index 506b65a..c437a03 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -11,6 +11,11 @@
__version__ = '$Id$'
+try:
+ from stdnum.exceptions import ValidationError as StdNumValidationError
+except ImportError:
+ StdNumValidationError = None
+
from pywikibot import Bot, Claim, ItemPage
from pywikibot.cosmetic_changes import CosmeticChangesToolkit, CANCEL_MATCH
@@ -25,6 +30,11 @@
WikibaseTestCase, ScriptMainTestCase,
)
from tests.bot_tests import TWNBotTestCase
+
+if StdNumValidationError:
+ AnyIsbnValidationException = (StdNumValidationError, IsbnExc)
+else:
+ AnyIsbnValidationException = IsbnExc
class TestCosmeticChangesISBN(DefaultDrySiteTestCase):
@@ -45,10 +55,18 @@
"""Test that it'll fail when the ISBN is
invalid."""
cc = CosmeticChangesToolkit(self.site, namespace=0)
- self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 0975229LOL') # Invalid
characters
- self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 0975229801') # Invalid
checksum
- self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 09752298') # Invalid
length
- self.assertRaises(Exception, cc.fix_ISBN, 'ISBN 09752X9801') # X in the
middle
+ # Invalid characters
+ self.assertRaises(AnyIsbnValidationException,
+ cc.fix_ISBN, 'ISBN 0975229LOL')
+ # Invalid checksum
+ self.assertRaises(AnyIsbnValidationException,
+ cc.fix_ISBN, 'ISBN 0975229801')
+ # Invalid length
+ self.assertRaises(AnyIsbnValidationException,
+ cc.fix_ISBN, 'ISBN 09752298')
+ # X in the middle
+ self.assertRaises(AnyIsbnValidationException,
+ cc.fix_ISBN, 'ISBN 09752X9801')
def test_ignore_invalid_isbn(self):
"""Test fixing ISBN numbers with an invalid
ISBN."""
diff --git a/tests/weblinkchecker_tests.py b/tests/weblinkchecker_tests.py
index e3682a7..2080d98 100644
--- a/tests/weblinkchecker_tests.py
+++ b/tests/weblinkchecker_tests.py
@@ -84,7 +84,10 @@
def test_invalid(self):
"""Test getting memento for invalid URL."""
- self.assertRaises(Exception, self._get_archive_url, 'invalid')
+ # memento_client raises 'Exception', not a subclass.
+ self.assertRaisesRegexp(
+ Exception, 'Only HTTP URIs are supported',
+ self._get_archive_url, 'invalid')
if __name__ == '__main__':
diff --git a/tox.ini b/tox.ini
index b737fee..a1bc548 100644
--- a/tox.ini
+++ b/tox.ini
@@ -95,9 +95,8 @@
# E402: module level import not at top of file; see T87409
# E731: do not assign a lambda expression, use a def; see I7b3db838
# H201: Except: format
-# H202: assertRaises Exception too broad
# P102,P103: string does contain unindexed parameters; see I36355923
-ignore =
E402,E731,D105,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H202,H236,H301,H404,H405,I100,I101,P102,P103
+ignore =
E402,E731,D105,D211,FI10,FI12,FI13,FI15,FI5,H101,H201,H236,H301,H404,H405,I100,I101,P102,P103
exclude = .tox,.git,./*.egg,ez_setup.py,build,externals,user-config.py,./scripts/i18n/*
max_line_length = 130
accept-encodings = utf-8
--
To view, visit
https://gerrit.wikimedia.org/r/260546
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I667d7ed3aa447412d99b5a503d09394b7c09a02d
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>