Divadsn has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/331601 )
Change subject: Replace assertRaises with assertRaisesRegex in http_tests.py ...................................................................... Replace assertRaises with assertRaisesRegex in http_tests.py Bug: T154281 Change-Id: I87707d58bab07886e8b35cb1030563df841c9844 --- M tests/http_tests.py 1 file changed, 10 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/01/331601/1 diff --git a/tests/http_tests.py b/tests/http_tests.py index ca90f76..ebbfe56 100644 --- a/tests/http_tests.py +++ b/tests/http_tests.py @@ -133,18 +133,19 @@ """HTTPS certificate test.""" + CERT_VERIFY_FAILED_RE = 'SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed' hostname = 'testssl-expire-r2i2.disig.sk' def test_https_cert_error(self): """Test if http.fetch respects disable_ssl_certificate_validation.""" - self.assertRaises(pywikibot.FatalServerError, + self.assertRaisesRegex(pywikibot.FatalServerError, self.CERT_VERIFY_FAILED_RE, http.fetch, uri='https://testssl-expire-r2i2.disig.sk/index.en.html') http.session.close() # clear the connection with warnings.catch_warnings(record=True) as warning_log: response = http.fetch( - uri='https://testssl-expire-r2i2.disig.sk/index.en.html', + uri='https://testssl-expire-r2i2.disig.sk/assertRaisesRegex(index.en.html', disable_ssl_certificate_validation=True) r = response.content self.assertIsInstance(r, unicode) @@ -152,7 +153,7 @@ http.session.close() # clear the connection # Verify that it now fails again - self.assertRaises(pywikibot.FatalServerError, + self.assertRaisesRegex(pywikibot.FatalServerError, self.CERT_VERIFY_FAILED_RE, http.fetch, uri='https://testssl-expire-r2i2.disig.sk/index.en.html') http.session.close() # clear the connection @@ -181,13 +182,13 @@ def test_http_504(self): """Test that a HTTP 504 raises the correct exception.""" - self.assertRaises(pywikibot.Server504Error, + self.assertRaisesRegex(pywikibot.Server504Error, 'Server httpbin.org timed out', http.fetch, uri=self.get_httpbin_url('/status/504')) def test_server_not_found(self): """Test server not found exception.""" - self.assertRaises(requests.exceptions.ConnectionError, + self.assertRaisesRegex(requests.exceptions.ConnectionError, 'Max retries exceeded with url: /w/api.php', http.fetch, uri='http://ru-sib.wikipedia.org/w/api.php', default_error_handling=True) @@ -195,7 +196,7 @@ def test_invalid_scheme(self): """Test invalid scheme.""" # A InvalidSchema is raised within requests - self.assertRaises(requests.exceptions.InvalidSchema, + self.assertRaisesRegex(requests.exceptions.InvalidSchema, 'No connection adapters were found for \'invalid://url\'', http.fetch, uri='invalid://url') @@ -421,6 +422,7 @@ """Test that HttpRequest correct handles the charsets given.""" + CODEC_CANT_DECODE_RE = 'codec can\'t decode byte' net = False STR = u'äöü' @@ -507,9 +509,9 @@ req = CharsetTestCase._create_request('utf16', CharsetTestCase.LATIN1_BYTES) self.assertEqual('utf16', req.charset) - self.assertRaises(UnicodeDecodeError, lambda: req.encoding) + self.assertRaisesRegex(UnicodeDecodeError, self.CODEC_CANT_DECODE_RE, lambda: req.encoding) self.assertEqual(req.raw, CharsetTestCase.LATIN1_BYTES) - self.assertRaises(UnicodeDecodeError, lambda: req.content) + self.assertRaisesRegex(UnicodeDecodeError, self.CODEC_CANT_DECODE_RE, lambda: req.content) class BinaryTestCase(TestCase): -- To view, visit https://gerrit.wikimedia.org/r/331601 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I87707d58bab07886e8b35cb1030563df841c9844 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Divadsn <divad.nnamtd...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits