jenkins-bot submitted this change.

View Change


Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[tests] Only run a sample of cache tests

Processing all cached files need moe than 5 minutes on CI.
To decrease test time only run a sample of tests.

Bug: T334777
Change-Id: I453d1168744e4b46a44486698c3c387d1ebef794
---
M tests/cache_tests.py
M scripts/maintenance/cache.py
2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/scripts/maintenance/cache.py b/scripts/maintenance/cache.py
index 1918d6a..400ff41 100755
--- a/scripts/maintenance/cache.py
+++ b/scripts/maintenance/cache.py
@@ -64,7 +64,7 @@
uniquedesc(entry)
"""
#
-# (C) Pywikibot team, 2014-2022
+# (C) Pywikibot team, 2014-2023
#
# Distributed under the terms of the MIT license.
#
@@ -74,6 +74,7 @@
import pickle
import sys
from pathlib import Path
+from random import sample
from typing import Optional

import pywikibot
@@ -219,7 +220,8 @@


def process_entries(cache_path, func, use_accesstime: Optional[bool] = None,
- output_func=None, action_func=None):
+ output_func=None, action_func=None, *,
+ tests: Optional[int] = None):
"""Check the contents of the cache.

This program tries to use file access times to determine whether
@@ -230,6 +232,7 @@

:param use_accesstime: Whether access times should be used. `None`
for detect, `False` for don't use and `True` for always use.
+ :param tests: Only process a test sample of files
"""
if not cache_path:
cache_path = os.path.join(pywikibot.config.base_dir,
@@ -245,6 +248,9 @@
else:
filenames = [cache_path]

+ if tests:
+ filenames = sample(filenames, min(len(filenames), tests))
+
for filepath in filenames:
filename = os.path.basename(filepath)
cache_dir = os.path.dirname(filepath)
@@ -260,7 +266,7 @@
continue

# Skip foreign python specific directory
- _, _, version = cache_path.partition('-')
+ *_, version = cache_path.partition('-')
if version and version[-1] != str(PYTHON_VERSION[0]):
pywikibot.error(
"Skipping {} directory, can't read content with python {}"
diff --git a/tests/cache_tests.py b/tests/cache_tests.py
index 761ec32..5b57083 100755
--- a/tests/cache_tests.py
+++ b/tests/cache_tests.py
@@ -34,7 +34,8 @@

def test_cache(self):
"""Test the apicache by doing _check_cache_entry over each entry."""
- cache.process_entries(join_cache_path(), self._check_cache_entry)
+ cache.process_entries(join_cache_path(), self._check_cache_entry,
+ tests=25)


if __name__ == '__main__': # pragma: no cover

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I453d1168744e4b46a44486698c3c387d1ebef794
Gerrit-Change-Number: 908943
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: D3r1ck01 <xsavitar.wiki@aol.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged