John Vandenberg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/260546

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(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/46/260546/1

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 ac5a94b..eb6dbc9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -78,7 +78,7 @@
     -rdocs/requirements-py3.txt
 
 [flake8]
-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: newchange
Gerrit-Change-Id: I667d7ed3aa447412d99b5a503d09394b7c09a02d
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to