Ryan10145 has uploaded a new change for review. ( 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 asserRaisesRegex. The latter has an extra parameter to match the exception message, allowing more more precision when checking an error. Bug: T154281 Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e --- M tests/isbn_tests.py 1 file changed, 10 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/34/399134/1 diff --git a/tests/isbn_tests.py b/tests/isbn_tests.py index df00417..bc31b0e 100644 --- a/tests/isbn_tests.py +++ b/tests/isbn_tests.py @@ -39,6 +39,8 @@ """Test CosmeticChanges ISBN fix.""" + ISBN_DIGITERROR_RE = 'The ISBN [0-9]+ is not [0-9]+ digits long.' + def test_valid_isbn(self): """Test ISBN.""" cc = CosmeticChangesToolkit(self.site, namespace=0) @@ -54,17 +56,17 @@ cc = CosmeticChangesToolkit(self.site, namespace=0) # Invalid characters - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 0975229LOL') + self.assertRaisesRegex(AnyIsbnValidationException, + self.ISBN_DIGITERROR_RE, cc.fix_ISBN, 'ISBN 0975229LOL') # Invalid checksum - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 0975229801') + self.assertRaisesRegex(AnyIsbnValidationException, + 'The ISBN checksum of [0-9]+ is incorrect.', cc.fix_ISBN, 'ISBN 0975229801') # Invalid length - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 09752298') + self.assertRaisesRegex(AnyIsbnValidationException, + self.ISBN_DIGITERROR_RE, cc.fix_ISBN, 'ISBN 09752298') # X in the middle - self.assertRaises(AnyIsbnValidationException, - cc.fix_ISBN, 'ISBN 09752X9801') + self.assertRaisesRegex(AnyIsbnValidationException, + 'The ISBN [0-9a-zA-Z]+ contains invalid characters.', 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: newchange Gerrit-Change-Id: I0386fd012d6b92dfa776cc8e55bfff265af40e2e Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ryan10145 <chang.ryan10...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits