Xqt has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/399348 )

Change subject: Replace assertRaises with assertRaisesRegex in isbn_tests.py
......................................................................

Replace assertRaises with assertRaisesRegex in isbn_tests.py

assertRaises is not as good of a test as assertRaisesRegex.
The latter has an extra parameter to match the exception message,
allowing more precision when checking an error.

Change restored after revert in Ib41b30

Bug: T154281
Change-Id: Id67d5b76c0dc5a70289478d842cd3ebdc28b1b85
---
M tests/isbn_tests.py
1 file changed, 28 insertions(+), 8 deletions(-)

Approvals:
  jenkins-bot: Verified
  Xqt: Looks good to me, approved



diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py
index fbe0bac..e4bbe26 100644
--- a/tests/isbn_tests.py
+++ b/tests/isbn_tests.py
@@ -41,6 +41,13 @@

     """Test CosmeticChanges ISBN fix."""

+    ISBN_DIGITERROR_RE = 'ISBN [0-9]+ is not [0-9]+ digits long'
+    ISBN_INVALIDERROR_RE = 'Invalid ISBN found'
+    ISBN_CHECKSUMERROR_RE = 'ISBN checksum of [0-9]+ is incorrect'
+    ISBN_INVALIDCHECKERROR_RE = 'checksum or check digit is invalid'
+    ISBN_INVALIDCHARERROR_RE = 'ISBN [0-9a-zA-Z]+ contains invalid characters'
+    ISBN_INVALIDLENGTHERROR_RE = 'The number has an invalid length'
+
     def test_valid_isbn(self):
         """Test ISBN."""
         cc = CosmeticChangesToolkit(self.site, namespace=0)
@@ -62,17 +69,30 @@
         cc = CosmeticChangesToolkit(self.site, namespace=0)

         # Invalid characters
-        self.assertRaises(AnyIsbnValidationException,
-                          cc.fix_ISBN, 'ISBN 0975229LOL')
+        self.assertRaisesRegex(AnyIsbnValidationException,
+                               '|'.join((self.ISBN_DIGITERROR_RE,
+                                         self.ISBN_INVALIDERROR_RE,
+                                         self.ISBN_INVALIDLENGTHERROR_RE)),
+                               cc.fix_ISBN, 'ISBN 0975229LOL')
         # Invalid checksum
-        self.assertRaises(AnyIsbnValidationException,
-                          cc.fix_ISBN, 'ISBN 0975229801')
+        self.assertRaisesRegex(AnyIsbnValidationException,
+                               '|'.join((self.ISBN_CHECKSUMERROR_RE,
+                                         self.ISBN_INVALIDERROR_RE,
+                                         self.ISBN_INVALIDLENGTHERROR_RE,
+                                         self.ISBN_INVALIDCHECKERROR_RE)),
+                               cc.fix_ISBN, 'ISBN 0975229801')
         # Invalid length
-        self.assertRaises(AnyIsbnValidationException,
-                          cc.fix_ISBN, 'ISBN 09752298')
+        self.assertRaisesRegex(AnyIsbnValidationException,
+                               '|'.join((self.ISBN_DIGITERROR_RE,
+                                         self.ISBN_INVALIDERROR_RE,
+                                         self.ISBN_INVALIDLENGTHERROR_RE)),
+                               cc.fix_ISBN, 'ISBN 09752298')
         # X in the middle
-        self.assertRaises(AnyIsbnValidationException,
-                          cc.fix_ISBN, 'ISBN 09752X9801')
+        self.assertRaisesRegex(AnyIsbnValidationException,
+                               '|'.join((self.ISBN_INVALIDCHARERROR_RE,
+                                         self.ISBN_INVALIDERROR_RE,
+                                         self.ISBN_INVALIDLENGTHERROR_RE)),
+                               cc.fix_ISBN, 'ISBN 09752X9801')

     def test_ignore_invalid_isbn(self):
         """Test fixing ISBN numbers with an invalid ISBN."""

--
To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/399348
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Id67d5b76c0dc5a70289478d842cd3ebdc28b1b85
Gerrit-Change-Number: 399348
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Dalba <[email protected]>
Gerrit-Reviewer: Hazard-SJ <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ryan10145 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged
_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to