jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/814235 )
Change subject: [IMPR] Replace assertRaises with assertRaisesRegex ......................................................................
[IMPR] Replace assertRaises with assertRaisesRegex
Bug: T154281 Change-Id: I373729013ae3899d91ea7d3d408a1a5563c00e5c --- M tests/aspects.py M tests/utils.py 2 files changed, 9 insertions(+), 4 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/tests/aspects.py b/tests/aspects.py index 084f649..0a260ae 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -264,7 +264,7 @@ self.assertCountEqual(gen_titles, titles)
def assertAPIError(self, code, info=None, callable_obj=None, *args, - **kwargs): + regex=None, **kwargs): """ Assert that a specific APIError wrapped around :py:obj:`assertRaises`.
@@ -288,7 +288,7 @@ """ msg = kwargs.pop('msg', None) return AssertAPIErrorContextManager( - code, info, msg, self).handle(callable_obj, args, kwargs) + code, info, msg, self, regex).handle(callable_obj, args, kwargs)
def require_modules(*required_modules): diff --git a/tests/utils.py b/tests/utils.py index 59d0532..e55b4d4 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -170,16 +170,21 @@ object given or calls the callable object. """
- def __init__(self, code, info, msg, test_case): + def __init__(self, code, info, msg, test_case, regex=None): """Create instance expecting the code and info.""" self.code = code self.info = info self.msg = msg self.test_case = test_case + self.regex = regex
def __enter__(self): """Enter this context manager and the unittest's context manager.""" - self.cm = self.test_case.assertRaises(APIError, msg=self.msg) + if self.regex: + self.cm = self.test_case.assertRaisesRegex(APIError, self.regex, + msg=self.msg) + else: + self.cm = self.test_case.assertRaises(APIError, msg=self.msg) self.cm.__enter__() return self.cm
pywikibot-commits@lists.wikimedia.org