jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[bugfix] only get HTTPStatus enum in site_detect check_response

- The description is used later within the exception message.
Instead of raising AttributeError a ClientError is raised then.
- Update tests accordingly.

Bug: T334728
Change-Id: If0eb80e5cf08115550ce6563b3759152256d2867
---
M tests/site_detect_tests.py
M pywikibot/site_detect.py
2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py
index 5dde965..c79983f 100644
--- a/pywikibot/site_detect.py
+++ b/pywikibot/site_detect.py
@@ -295,7 +295,7 @@
]: # highest http status code first
if response.status_code >= status_code:
try:
- status = HTTPStatus(response.status_code).description
+ status = HTTPStatus(response.status_code)
except ValueError as err:
m = re.search(r'\d{3}', err.args[0], flags=re.ASCII)
if not m:
diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py
index 024f829..ca3be3c 100755
--- a/tests/site_detect_tests.py
+++ b/tests/site_detect_tests.py
@@ -14,7 +14,7 @@
import requests.exceptions as requests_exceptions

import pywikibot
-from pywikibot.exceptions import ServerError
+from pywikibot.exceptions import ClientError, ServerError
from pywikibot.site_detect import MWSite

from tests.aspects import PatchingTestCase, TestCase
@@ -38,14 +38,14 @@
self.assertIsInstance(MWSite(url), MWSite)

def assertNoSite(self, url: str):
- """
- Assert a url is not a MediaWiki site.
+ """Assert a url is not a MediaWiki site.

:param url: Url of tested site
:raises AssertionError: Site under url is MediaWiki powered
"""
with self.assertRaises((AttributeError,
- ConnectionError,
+ ClientError,
+ ConnectionError, # different from requests
RuntimeError,
ServerError,
requests_exceptions.ConnectionError,

To view, visit change 908831. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: If0eb80e5cf08115550ce6563b3759152256d2867
Gerrit-Change-Number: 908831
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged