jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1329378?usp=email )
Change subject: archivebot: Replace OrderedDict with dict ......................................................................
archivebot: Replace OrderedDict with dict
Python 3.9 and later guarantee dictionary insertion ordering. Use a dict literal for PageArchiver attributes while preserving the parameter order used when saving configuration templates.
Change-Id: Ib24b616c8369158065ea21b10294cd1195184c6d --- M scripts/archivebot.py M tests/archivebot_tests.py 2 files changed, 32 insertions(+), 8 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py index f5f6dbe..8665970 100755 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -203,7 +203,7 @@ import signal import threading import time -from collections import OrderedDict, defaultdict +from collections import defaultdict from contextlib import nullcontext from hashlib import md5 from math import ceil @@ -615,12 +615,12 @@ :param force: override security value :param asynchronous: asynchronous processing activated """ - self.attributes = OrderedDict([ - ('archive', ['', False]), - ('algo', ['old(24h)', False]), - ('counter', ['1', False]), - ('maxarchivesize', ['200K', False]), - ]) + self.attributes = { + 'archive': ['', False], + 'algo': ['old(24h)', False], + 'counter': ['1', False], + 'maxarchivesize': ['200K', False], + } self.salt = salt self.force = force self.sort = sort diff --git a/tests/archivebot_tests.py b/tests/archivebot_tests.py index d04cf18..39cd394 100755 --- a/tests/archivebot_tests.py +++ b/tests/archivebot_tests.py @@ -340,6 +340,24 @@ family = 'wikipedia' code = 'test'
+ def test_attributes_order(self) -> None: + """Test order when attributes are added or updated.""" + site = self.get_site() + page = pywikibot.Page(site, 'Talk:For-pywikibot-archivebot-01') + template = pywikibot.Page(site, 'Template:Pywikibot_archivebot') + archiver = archivebot.PageArchiver(page, template, '') + + archiver.set_attr('minthreadsleft', '3') + archiver.set_attr('algo', 'old(60d)') + + self.assertEqual( + list(archiver.attributes), + ['archive', 'algo', 'counter', 'maxarchivesize', + 'minthreadsleft']) + self.assertEqual( + archiver.saveables(), + ['archive', 'algo', 'minthreadsleft']) + def testLoadConfigInTemplateNamespace(self) -> None: """Test loading of config with TEMPLATE_PAGE in Template ns.
@@ -358,10 +376,16 @@ tmpl_without_ns = pywikibot.Page(site, 'Pywikibot_archivebot', ns=10)
try: - archivebot.PageArchiver(page, tmpl_with_ns, '') + archiver = archivebot.PageArchiver(page, tmpl_with_ns, '') except Error as e: # pragma: no cover self.fail(f'PageArchiver() raised {e}!')
+ self.assertIs(type(archiver.attributes), dict) + self.assertEqual( + list(archiver.attributes), + ['archive', 'algo', 'counter', 'maxarchivesize']) + self.assertEqual(archiver.saveables(), ['archive', 'algo']) + try: archivebot.PageArchiver(page, tmpl_without_ns, '') except Error as e: # pragma: no cover
pywikibot-commits@lists.wikimedia.org