Xqt has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/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, 21 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/48/399348/1 diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py index df00417..fc48a08 100644 --- a/tests/isbn_tests.py +++ b/tests/isbn_tests.py @@ -39,6 +39,11 @@ """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_INVALIDCHARERROR_RE = 'ISBN [0-9a-zA-Z]+ contains invalid characters' + def test_valid_isbn(self): """Test ISBN.""" cc = CosmeticChangesToolkit(self.site, namespace=0) @@ -54,17 +59,25 @@ cc = CosmeticChangesToolkit(self.site, namespace=0) # Invalid characters - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 0975229LOL') + self.assertRaisesRegex(AnyIsbnValidationException, + (self.ISBN_DIGITERROR_RE + '|' + + self.ISBN_INVALIDERROR_RE), + cc.fix_ISBN, 'ISBN 0975229LOL') # Invalid checksum - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 0975229801') + self.assertRaisesRegex(AnyIsbnValidationException, + (self.ISBN_CHECKSUMERROR_RE + '|' + + self.ISBN_INVALIDERROR_RE), + cc.fix_ISBN, 'ISBN 0975229801') # Invalid length - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 09752298') + self.assertRaisesRegex(AnyIsbnValidationException, + (self.ISBN_DIGITERROR_RE + '|' + + self.ISBN_INVALIDERROR_RE), + cc.fix_ISBN, 'ISBN 09752298') # X in the middle - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 09752X9801') + self.assertRaisesRegex(AnyIsbnValidationException, + (self.ISBN_INVALIDCHARERROR_RE + '|' + + self.ISBN_INVALIDERROR_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/399348 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id67d5b76c0dc5a70289478d842cd3ebdc28b1b85 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Xqt <i...@gno.de> Gerrit-Reviewer: Ryan10145 <chang.ryan10...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits