diff --git a/test/pmb_test/const.py b/test/pmb_test/const.py index 94d78171..ad219018 100644 --- a/test/pmb_test/const.py +++ b/test/pmb_test/const.py @@ -3,4 +3,4 @@ import pmb.config -testdata = pmb.config.pmb_src + "/test/testdata" +testdata = pmb.config.pmb_src / "test/testdata" diff --git a/test/pmb_test/git.py b/test/pmb_test/git.py index 76667641..b4112cce 100644 --- a/test/pmb_test/git.py +++ b/test/pmb_test/git.py @@ -64,4 +64,4 @@ def prepare_tmpdir(args: PmbArgs, monkeypatch, tmpdir): return path_local, run_git def copy_dotgit(args: PmbArgs, tmpdir): - shutil.copytree(args.aports + "/.git", tmpdir + "/.git", ignore_dangling_symlinks=True) + shutil.copytree(args.aports / ".git", tmpdir + "/.git", ignore_dangling_symlinks=True) diff --git a/test/test_apk.py b/test/test_apk.py index ee8b5f72..2ca648f0 100644 --- a/test/test_apk.py +++ b/test/test_apk.py @@ -1,14 +1,18 @@ # Copyright 2023 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later import fnmatch +from typing import List import pytest import sys +from pmb.core.types import PathString import pmb_test # noqa import pmb.build import pmb.chroot.apk from pmb.core import Chroot +cmds_progress: List[PathString] = [] +cmds: List[PathString] = [] @pytest.fixture def args(tmpdir, request): diff --git a/test/test_apk_static.py b/test/test_apk_static.py index 6d5987b8..9b53dd7b 100644 --- a/test/test_apk_static.py +++ b/test/test_apk_static.py @@ -2,6 +2,7 @@ # SPDX-License-Identifier: GPL-3.0-or-later import os import copy +from pathlib import Path import sys import tarfile import glob @@ -28,42 +29,42 @@ def args(request): def test_read_signature_info(args: PmbArgs): # Tempfolder inside chroot for fake apk files - tmp_path = "/tmp/test_read_signature_info" - tmp_path_outside = pmb.config.work / "chroot_native" + tmp_path + tmp_path = Path("/tmp/test_read_signature_info") + tmp_path_outside = pmb.config.work / "chroot_native" / tmp_path if os.path.exists(tmp_path_outside): pmb.chroot.root(args, ["rm", "-r", tmp_path]) pmb.chroot.user(args, ["mkdir", "-p", tmp_path]) # No signature found - pmb.chroot.user(args, ["tar", "-czf", tmp_path + "/no_sig.apk", + pmb.chroot.user(args, ["tar", "-czf", tmp_path / "no_sig.apk", "/etc/issue"]) - with tarfile.open(tmp_path_outside + "/no_sig.apk", "r:gz") as tar: + with tarfile.open(tmp_path_outside / "no_sig.apk", "r:gz") as tar: with pytest.raises(RuntimeError) as e: pmb.chroot.apk_static.read_signature_info(tar) assert "Could not find signature" in str(e.value) # Signature file with invalid name - pmb.chroot.user(args, ["mkdir", "-p", tmp_path + "/sbin"]) - pmb.chroot.user(args, ["cp", "/etc/issue", tmp_path + - "/sbin/apk.static.SIGN.RSA.invalid.pub"]) - pmb.chroot.user(args, ["tar", "-czf", tmp_path + "/invalid_sig.apk", + pmb.chroot.user(args, ["mkdir", "-p", tmp_path / "sbin"]) + pmb.chroot.user(args, ["cp", "/etc/issue", tmp_path / + "sbin/apk.static.SIGN.RSA.invalid.pub"]) + pmb.chroot.user(args, ["tar", "-czf", tmp_path / "invalid_sig.apk", "sbin/apk.static.SIGN.RSA.invalid.pub"], working_dir=tmp_path) - with tarfile.open(tmp_path_outside + "/invalid_sig.apk", "r:gz") as tar: + with tarfile.open(tmp_path_outside / "invalid_sig.apk", "r:gz") as tar: with pytest.raises(RuntimeError) as e: pmb.chroot.apk_static.read_signature_info(tar) assert "Invalid signature key" in str(e.value) # Signature file with realistic name - path = glob.glob(pmb.config.apk_keys_path + "/*.pub")[0] + path = list(pmb.config.apk_keys_path.glob("/*.pub"))[0] name = os.path.basename(path) path_archive = "sbin/apk.static.SIGN.RSA." + name pmb.chroot.user(args, ["mv", - f"{tmp_path}/sbin/apk.static.SIGN.RSA.invalid.pub", - f"{tmp_path}/{path_archive}"]) - pmb.chroot.user(args, ["tar", "-czf", tmp_path + "/realistic_name_sig.apk", + tmp_path / "sbin/apk.static.SIGN.RSA.invalid.pub", + tmp_path / path_archive]) + pmb.chroot.user(args, ["tar", "-czf", tmp_path / "realistic_name_sig.apk", path_archive], working_dir=tmp_path) - with tarfile.open(f"{tmp_path_outside}/realistic_name_sig.apk", "r:gz")\ + with tarfile.open(tmp_path_outside / "realistic_name_sig.apk", "r:gz")\ as tar: sigfilename, sigkey_path = pmb.chroot.apk_static.read_signature_info( tar) diff --git a/test/test_shell_escape.py b/test/test_shell_escape.py index 5055b290..d27286ab 100644 --- a/test/test_shell_escape.py +++ b/test/test_shell_escape.py @@ -1,7 +1,8 @@ # Copyright 2023 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later import sys -from pmb.core.types import PmbArgs +from typing import Any +from pmb.core.types import Env, PmbArgs import pytest import pmb_test # noqa @@ -58,12 +59,12 @@ def test_shell_escape(args: PmbArgs): def test_shell_escape_env(args: PmbArgs): key = "PMBOOTSTRAP_TEST_ENVIRONMENT_VARIABLE" value = "long value with spaces and special characters: '\"\\!$test" - env = {key: value} + env: Env = {key: value} cmd = ["sh", "-c", "env | grep " + key + " | grep -v SUDO_COMMAND"] ret = key + "=" + value + "\n" copy = list(cmd) - func = pmb.helpers.run.user + func: Any = pmb.helpers.run.user assert func(args, cmd, output_return=True, env=env) == ret assert cmd == copy @@ -83,34 +84,30 @@ def test_shell_escape_env(args: PmbArgs): def test_flat_cmd_simple(): func = pmb.helpers.run_core.flat_cmd cmd = ["echo", "test"] - working_dir = None ret = "echo test" - env = {} - assert func(cmd, working_dir, env) == ret + env: Env = {} + assert func(cmd, env=env) == ret def test_flat_cmd_wrap_shell_string_with_spaces(): func = pmb.helpers.run_core.flat_cmd cmd = ["echo", "string with spaces"] - working_dir = None ret = "echo 'string with spaces'" - env = {} - assert func(cmd, working_dir, env) == ret + env: Env = {} + assert func(cmd, env=env) == ret def test_flat_cmd_wrap_env_simple(): func = pmb.helpers.run_core.flat_cmd cmd = ["echo", "test"] - working_dir = None ret = "JOBS=5 echo test" - env = {"JOBS": "5"} - assert func(cmd, working_dir, env) == ret + env: Env = {"JOBS": "5"} + assert func(cmd, env=env) == ret def test_flat_cmd_wrap_env_spaces(): func = pmb.helpers.run_core.flat_cmd cmd = ["echo", "test"] - working_dir = None ret = "JOBS=5 TEST='spaces string' echo test" - env = {"JOBS": "5", "TEST": "spaces string"} - assert func(cmd, working_dir, env) == ret + env: Env = {"JOBS": "5", "TEST": "spaces string"} + assert func(cmd, env=env) == ret