jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/393990 )
Change subject: Change to use assertRaisesRegex in file_tests.py ...................................................................... Change to use assertRaisesRegex in file_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: I8a30b49dd6506e0e0f0d0c7cf7affcabc20bfa75 --- M tests/file_tests.py 1 file changed, 36 insertions(+), 7 deletions(-) Approvals: Dalba: Looks good to me, approved jenkins-bot: Verified diff --git a/tests/file_tests.py b/tests/file_tests.py index 324f2c1..f4f8584 100644 --- a/tests/file_tests.py +++ b/tests/file_tests.py @@ -8,6 +8,7 @@ from __future__ import absolute_import, unicode_literals import os +import re import pywikibot @@ -73,7 +74,10 @@ self.assertTrue(commons_file.get_file_url()) self.assertIn('/wikipedia/commons/', itwp_file.get_file_url()) - self.assertRaises(pywikibot.NoPage, itwp_file.get) + with self.assertRaisesRegex( + pywikibot.NoPage, + (r'Page \[\[(wikipedia:|)it:%s\]\] doesn\'t exist.' % title)): + itwp_file.get() def testLocalOnly(self): """Test fileIsShared() on file page with local file only.""" @@ -93,10 +97,23 @@ self.assertFalse(commons_file.exists()) self.assertFalse(enwp_file.fileIsShared()) - self.assertRaises(pywikibot.NoPage, commons_file.fileIsShared) - self.assertRaises(pywikibot.NoPage, commons_file.get_file_url) - self.assertRaises(pywikibot.NoPage, commons_file.get) + page_doesnt_exist_exc_regex = re.escape( + 'Page [[commons:%s]] doesn\'t exist.' % title) + with self.assertRaisesRegex( + pywikibot.NoPage, + page_doesnt_exist_exc_regex): + commons_file.fileIsShared() + + with self.assertRaisesRegex( + pywikibot.NoPage, + page_doesnt_exist_exc_regex): + commons_file.get_file_url() + + with self.assertRaisesRegex( + pywikibot.NoPage, + page_doesnt_exist_exc_regex): + commons_file.get() def testOnBoth(self): """Test fileIsShared() on file page with both local and shared file.""" @@ -155,7 +172,11 @@ site = self.get_site() image = pywikibot.FilePage(site, u'File:NoPage') self.assertFalse(image.exists()) - with self.assertRaises(pywikibot.NoPage): + + with self.assertRaisesRegex( + pywikibot.NoPage, + (r'Page \[\[(wikipedia\:|)test:File:NoPage\]\] ' + r'doesn\'t exist\.')): image = image.latest_file_info def test_file_info_with_no_file(self): @@ -163,7 +184,11 @@ site = self.get_site() image = pywikibot.FilePage(site, u'File:Test with no image') self.assertTrue(image.exists()) - with self.assertRaises(pywikibot.PageRelatedError): + with self.assertRaisesRegex( + pywikibot.PageRelatedError, + (r'loadimageinfo: Query on ' + r'\[\[(wikipedia\:|)test:File:Test with no image\]\]' + r' returned no imageinfo')): image = image.latest_file_info @@ -278,7 +303,11 @@ """Test not existing download.""" page = pywikibot.FilePage(self.site, 'File:Albert Einstein.jpg_notexisting') filename = join_images_path('Albert Einstein.jpg') - with self.assertRaises(pywikibot.NoPage): + + with self.assertRaisesRegex( + pywikibot.NoPage, + re.escape('Page [[commons:File:Albert Einstein.jpg ' + 'notexisting]] doesn\'t exist.')): page.download(filename) -- To view, visit https://gerrit.wikimedia.org/r/393990 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8a30b49dd6506e0e0f0d0c7cf7affcabc20bfa75 Gerrit-PatchSet: 6 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Rafidaslam <rafidt...@gmail.com> Gerrit-Reviewer: Dalba <dalba.w...@gmail.com> Gerrit-Reviewer: John Vandenberg <jay...@gmail.com> Gerrit-Reviewer: Magul <tomasz.magul...@gmail.com> Gerrit-Reviewer: Rafidaslam <rafidt...@gmail.com> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: Zoranzoki21 <zorandori4...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits