From 3c4080e8f537b6d79e619b63c07d58915249997c Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Thu, 3 Nov 2022 19:19:40 +0100 Subject: [PATCH] CI: make test_unreferenced_files more generic (MR 3608) Prepare to add a new test making use of the parse_source_from_checksums() function in test_unreferenced_files.py by extending the function to not only return the checksum file names, but also the checksums. Also rename the file from test_unreferenced_files.py to test_source.py. --- ...t_unreferenced_files.py => test_source.py} | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) rename .ci/testcases/{test_unreferenced_files.py => test_source.py} (85%) diff --git a/.ci/testcases/test_unreferenced_files.py b/.ci/testcases/test_source.py similarity index 85% rename from .ci/testcases/test_unreferenced_files.py rename to .ci/testcases/test_source.py index bd15afa72..a9a3d0ca8 100644 --- a/.ci/testcases/test_unreferenced_files.py +++ b/.ci/testcases/test_source.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 -# Copyright 2021 Oliver Smith +# Copyright 2022 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later +# Various checks on source= in the APKBUILDs import glob import pytest @@ -21,12 +22,13 @@ def parse_source_from_checksums(args, apkbuild_path): to parse shell code (like in postmarketos-base). :param apkbuild_path: full path to the APKBUILD - :returns: list of parsed "source" files, e.g.: - ["first.patch", "second.patch"] + :returns: dict of parsed "source" filenames and checksums, e.g.: + {"first.patch": "b4dc4f3…", + "second.patch": "b4dc4f3…"} """ start = 'sha512sums="' in_block = False - ret = [] + ret = {} with open(apkbuild_path, encoding="utf-8") as handle: for line in handle.readlines(): @@ -43,18 +45,21 @@ def parse_source_from_checksums(args, apkbuild_path): continue try: - _, filename = line.rstrip().split(" ", 2) + checksum, filename = line.rstrip().split(" ", 2) except ValueError: raise ValueError("Failed to parse checksums. Try to delete the" " checksums and generate them again with" f" 'pmbootstrap checksum': {apkbuild_path}") + # Cut off 'sha512sums="' if the first checksum is in that line + if checksum.startswith(start): + checksum = checksum[len(start):] + # Find end if filename.endswith('"'): - ret += [filename[:-1]] - break + filename = filename[:-1] - ret += [filename] + ret[filename] = checksum return ret