jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/831181 )
Change subject: [bugfix] Fix AttributeError in memento.get_closest_memento_url ......................................................................
[bugfix] Fix AttributeError in memento.get_closest_memento_url
Also update tests to detect such bug.
Bug: T317466 Change-Id: Icce420659458ecc56cc2c3276eaea7b0339cae48 --- M pywikibot/data/memento.py M tests/memento_tests.py 2 files changed, 7 insertions(+), 10 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/data/memento.py b/pywikibot/data/memento.py index 55d3cfc..93bc2ca 100644 --- a/pywikibot/data/memento.py +++ b/pywikibot/data/memento.py @@ -311,7 +311,7 @@ timegate_uri: Optional[str] = None): """Get most recent memento for url.""" if not when: - when = datetime.datetime.now() + when = datetime.now()
mc = MementoClient() if timegate_uri: diff --git a/tests/memento_tests.py b/tests/memento_tests.py index b60aec9..cfeb15e 100755 --- a/tests/memento_tests.py +++ b/tests/memento_tests.py @@ -1,18 +1,19 @@ #!/usr/bin/python3 -"""weblinkchecker test module.""" +"""memento client test module.""" # # (C) Pywikibot team, 2015-2022 # # Distributed under the terms of the MIT license. # -import datetime import unittest from contextlib import suppress +from datetime import datetime from urllib.parse import urlparse
from requests.exceptions import ConnectionError as RequestsConnectionError
from tests.aspects import TestCase, require_modules +from tests.utils import skipping
@require_modules('memento_client') @@ -26,14 +27,10 @@ get_closest_memento_url, )
- if date_string is None: - when = datetime.datetime.now() - else: - when = datetime.datetime.strptime(date_string, '%Y%m%d') - try: + when = (datetime.strptime(date_string, '%Y%m%d') + if date_string else None) + with skipping(RequestsConnectionError, MementoClientException): result = get_closest_memento_url(url, when, self.timegate_uri) - except (RequestsConnectionError, MementoClientException) as e: - self.skipTest(e) return result
pywikibot-commits@lists.wikimedia.org