jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/399134 )
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. Bug: T154281 Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e --- M tests/isbn_tests.py 1 file changed, 21 insertions(+), 8 deletions(-) Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified 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/399134 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e Gerrit-PatchSet: 11 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ryan10145 <chang.ryan10...@gmail.com> Gerrit-Reviewer: Dalba <dalba.w...@gmail.com> Gerrit-Reviewer: Framawiki <framaw...@tools.wmflabs.org> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Ryan10145 <chang.ryan10...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits