From 042ea0c0604c96e34da9f66775edc2cd868e84ae Mon Sep 17 00:00:00 2001 From: xqt Date: Sat, 7 Dec 2024 09:59:31 +0100 Subject: [PATCH] cleanup: Drop support for MediaWiki < 1.31 Also update tests: - use 'lobbypedia' instead of 'infogalactic' for logentries test - remove unreachable sites from site_detect_tests Bug: T378984 Change-Id: I9f33aa6e2ca8ebcda77b8e05ad45e62c66e24bc7 --- pywikibot/site/_apisite.py | 9 ++++----- pywikibot/site_detect.py | 4 ++-- pywikibot/tools/__init__.py | 8 ++++++++ tests/logentries_tests.py | 21 ++++++++++----------- tests/site_detect_tests.py | 7 +------ 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py index f538551cf8..089adee340 100644 --- a/pywikibot/site/_apisite.py +++ b/pywikibot/site/_apisite.py @@ -51,7 +51,7 @@ UnknownExtensionError, ) from pywikibot.site._basesite import BaseSite -from pywikibot.site._decorators import need_right, need_version +from pywikibot.site._decorators import need_right from pywikibot.site._extensions import ( EchoMixin, FlowMixin, @@ -1235,10 +1235,10 @@ def version(self) -> str: pywikibot.error(msg) raise - if MediaWikiVersion(version) < '1.27': + if MediaWikiVersion(version) < '1.31': raise RuntimeError(f'Pywikibot "{pywikibot.__version__}" does not ' - f'support MediaWiki "{version}".\n' - f'Use Pywikibot prior to "8.0" branch instead.') + f'support MediaWiki "{version}".\nUse ' + f'Pywikibot prior to "10.0" branch instead.') return version @property @@ -2746,7 +2746,6 @@ def protection_types(self) -> set[str]: """ return set(self.siteinfo.get('restrictions')['types']) - @need_version('1.27.3') def protection_levels(self) -> set[str]: """Return the protection levels available on this site. diff --git a/pywikibot/site_detect.py b/pywikibot/site_detect.py index f1b2256b60..1c58945865 100644 --- a/pywikibot/site_detect.py +++ b/pywikibot/site_detect.py @@ -26,7 +26,7 @@ SERVER_DB_ERROR_MSG = \ '

Sorry! This site is experiencing technical difficulties.

' -MIN_VERSION = MediaWikiVersion('1.27') +MIN_VERSION = MediaWikiVersion('1.31') class MWSite: @@ -40,7 +40,7 @@ def __init__(self, fromurl, **kwargs) -> None: occurred while loading the site :raises Timeout: a timeout occurred while loading the site :raises RuntimeError: Version not found or version less than - 1.27 + 1.31 """ fromurl = removesuffix(fromurl, '$1') diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py index 79060f2ed9..3a9ed6c85d 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -496,6 +496,14 @@ def __str__(self) -> str: """Return version number with optional suffix.""" return '.'.join(str(v) for v in self.version) + self.suffix + def __repr__(self) -> str: + """Return version number representation, mainly used by tests. + + .. versionadded:: 10.0 + + """ + return f"'{self}'" + def __eq__(self, other: Any) -> bool: if isinstance(other, str): other = MediaWikiVersion(other) diff --git a/tests/logentries_tests.py b/tests/logentries_tests.py index 2aa90ce959..1d74f6faad 100755 --- a/tests/logentries_tests.py +++ b/tests/logentries_tests.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 -"""Test logentries module.""" +"""Test :mod:`logentries` module.""" # -# (C) Pywikibot team, 2015-2023 +# (C) Pywikibot team, 2015-2024 # # Distributed under the terms of the MIT license. # @@ -28,11 +28,10 @@ class TestLogentriesBase(TestCase): """Base class for log entry tests. - It uses the German Wikipedia for a current representation of the - log entries and the test Wikipedia for the future representation. - It also tests on a wiki with MW <= 1.27 to check that the module - works with older wikis. It currently uses infogalacticwiki which as - of this commit uses 1.27.1. + It uses the German Wikipedia for a current representation of the log + entries and the test Wikipedia for the future representation. It + also tests on an older wiki to check that the module works with it. + It currently uses lobbypedia which as of this commit uses 1.31.6. """ sites = { @@ -52,9 +51,9 @@ class TestLogentriesBase(TestCase): 'target': None, }, 'old': { - 'family': AutoFamily('infogalactic', - 'https://infogalactic.com/info/Main_Page'), - 'code': 'en', + 'family': AutoFamily('lobbypedia', + 'https://lobbypedia.de/wiki/Hauptseite'), + 'code': 'de', 'target': None, } } @@ -65,7 +64,7 @@ def _get_logentry(self, logtype): # This is an assertion as the tests don't make sense with newer # MW versions and otherwise it might not be visible that the test # isn't run on an older wiki. - self.assertEqual(self.site.mw_version, '1.27.1') + self.assertEqual(self.site.mw_version, '1.31.6') with skipping(StopIteration, msg=f'No entry found for {logtype!r}'): diff --git a/tests/site_detect_tests.py b/tests/site_detect_tests.py index 3c18a1a6bb..9fa4a5f44b 100755 --- a/tests/site_detect_tests.py +++ b/tests/site_detect_tests.py @@ -69,26 +69,21 @@ class MediaWikiSiteTestCase(SiteDetectionTestCase): non_standard_version_sites = ( 'https://wiki.gentoo.org/wiki/$1', - 'https://www.arabeyes.org/$1', ) old_version_sites = ( 'http://tfwiki.net/wiki/$1', # 1.19.5-1+deb7u1 - 'http://www.hrwiki.org/index.php/$1', # v 1.15.4 'http://www.thelemapedia.org/index.php/$1', 'http://www.werelate.org/wiki/$1', - 'http://www.otterstedt.de/wiki/index.php/$1', 'https://en.wikifur.com/wiki/$1', # 1.23.16 + 'https://www.arabeyes.org/$1', # non standard 1.28.0 ) no_sites = ( - 'http://www.imdb.com/name/nm$1/', - 'http://www.ecyrd.com/JSPWiki/Wiki.jsp?page=$1', 'http://www.tvtropes.org/pmwiki/pmwiki.php/Main/$1', 'http://c2.com/cgi/wiki?$1', 'https://phabricator.wikimedia.org/$1', 'http://www.merriam-webster.com/' - 'cgi-bin/dictionary?book=Dictionary&va=$1', 'http://arxiv.org/abs/$1', # looks like a MW site but isn't, api is redirected to # https://foundation.wikimedia.org