jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/396576 )
Change subject: Replace assertRaises with assertRaisesRegex in category_tests.py ......................................................................
Replace assertRaises with assertRaisesRegex in category_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: Ia941decd329640a4e043208b52e5ce581b2bf0c0 --- M tests/category_tests.py 1 file changed, 11 insertions(+), 4 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved MtDu: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/tests/category_tests.py b/tests/category_tests.py index e4b4ba1..0d3f2d6 100644 --- a/tests/category_tests.py +++ b/tests/category_tests.py @@ -17,6 +17,9 @@
"""Test Category object."""
+ NOCATEGORYNAMESPACE_RE = ''(.*?)' is not in the category namespace!' + NOREDIRECTPAGE_RE = 'Page [[(.*?)]] is not a redirect page.' + family = 'wikipedia' code = 'en'
@@ -25,7 +28,8 @@ def test_init(self): """Test the category's __init__ for one condition that can't be dry.""" site = self.get_site() - self.assertRaises(ValueError, pywikibot.Category, site, 'Wikipedia:Test') + self.assertRaisesRegex(ValueError, self.NOCATEGORYNAMESPACE_RE, + pywikibot.Category, site, 'Wikipedia:Test')
def test_is_empty(self): """Test if category is empty or not.""" @@ -146,13 +150,15 @@ self.assertEqual(tgt, cat2)
# Raise exception if target is fetched for non Category redirects. - self.assertRaises(pywikibot.IsNotRedirectPage, - cat2.getCategoryRedirectTarget) + self.assertRaisesRegex(pywikibot.IsNotRedirectPage, + self.NOREDIRECTPAGE_RE, cat2.getCategoryRedirectTarget)
class TestCategoryDryObject(TestCase):
"""Test the category object with dry tests.""" + + NOCATEGORYNAMESPACE_RE = ''(.*?)' is not in the category namespace!'
family = 'wikipedia' code = 'en' @@ -178,7 +184,8 @@ self.assertTrue(cat_dup_ns.title(withNamespace=False), 'Page:Foo') self.assertTrue(cat_dup_ns.namespace(), 14)
- self.assertRaises(ValueError, pywikibot.Category, site, 'Talk:Foo') + self.assertRaisesRegex(ValueError, self.NOCATEGORYNAMESPACE_RE, + pywikibot.Category, site, 'Talk:Foo')
def test_section(self): """Test the section method."""
pywikibot-commits@lists.wikimedia.org