enforce E501 in test/ (MR 2058)

This commit is contained in:
Caio Fontes 2021-05-19 16:43:36 -03:00 committed by Oliver Smith
parent f3b3fe906b
commit 27746db188
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
8 changed files with 51 additions and 36 deletions

View File

@ -57,11 +57,13 @@ def test_read_signature_info(args):
path = glob.glob(pmb.config.apk_keys_path + "/*.pub")[0]
name = os.path.basename(path)
path_archive = "sbin/apk.static.SIGN.RSA." + name
pmb.chroot.user(args, ["mv", tmp_path + "/sbin/apk.static.SIGN.RSA.invalid.pub",
tmp_path + "/" + path_archive])
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",
path_archive], working_dir=tmp_path)
with tarfile.open(tmp_path_outside + "/realistic_name_sig.apk", "r:gz") as tar:
with tarfile.open(f"{tmp_path_outside}/realistic_name_sig.apk", "r:gz")\
as tar:
sigfilename, sigkey_path = pmb.chroot.apk_static.read_signature_info(
tar)
assert sigfilename == path_archive
@ -85,8 +87,8 @@ def test_signature_verification(args, tmpdir):
os.remove(args.work + "/apk.static")
version = pmb.parse.apkindex.package(args, "apk-tools-static")["version"]
apk_path = pmb.chroot.apk_static.download(args,
"apk-tools-static-" + version + ".apk")
apk_path = pmb.chroot.apk_static.download(
args, f"apk-tools-static-{version}.apk")
# Extract to temporary folder
with tarfile.open(apk_path, "r:gz") as tar:

View File

@ -37,7 +37,8 @@ def args(tmpdir, request):
# Copy the linux-lg-mako aport (we currently copy patches from there)
pmb.helpers.run.user(args, ["mkdir", "-p", tmpdir + "/device/testing"])
path_mako = args._aports_real + "/device/testing/linux-lg-mako"
pmb.helpers.run.user(args, ["cp", "-r", path_mako, tmpdir + "/device/testing"])
pmb.helpers.run.user(args, ["cp", "-r", path_mako,
f"{tmpdir}/device/testing"])
# Copy pmaports.cfg
shutil.copy(f"{pmb_test.const.testdata}/pmaports.cfg", args.aports)
@ -46,7 +47,8 @@ def args(tmpdir, request):
def generate(args, monkeypatch, answers):
"""
Generate the device-new-device and linux-new-device aports (with a patched pmb.helpers.cli()).
Generate the device-new-device and linux-new-device aports (with a patched
pmb.helpers.cli()).
:returns: (deviceinfo, apkbuild, apkbuild_linux) - the parsed dictionaries
of the created files, as returned by pmb.parse.apkbuild() and
@ -69,12 +71,13 @@ def generate(args, monkeypatch, answers):
pmb.aportgen.generate(args, "linux-testsuite-testdevice")
monkeypatch.undo()
apkbuild_path = (args.aports + "/device/testing/device-testsuite-testdevice/"
"APKBUILD")
apkbuild_path = (f"{args.aports}/device/testing/"
"device-testsuite-testdevice/APKBUILD")
apkbuild_path_linux = (args.aports + "/device/testing/"
"linux-testsuite-testdevice/APKBUILD")
# The build fails if the email is not a valid email, so remove them just for tests
# The build fails if the email is not a valid email, so remove them just
# for tests
remove_contributor_maintainer_lines(args, apkbuild_path)
remove_contributor_maintainer_lines(args, apkbuild_path_linux)

View File

@ -23,7 +23,8 @@ def args(request, tmpdir):
apkindex_path = str(tmpdir) + "/APKINDEX.tar.gz"
open(apkindex_path, "a").close()
lastmod = os.path.getmtime(apkindex_path)
args.cache["apkindex"][apkindex_path] = {"lastmod": lastmod, "multiple": {}}
args.cache["apkindex"][apkindex_path] = {"lastmod": lastmod,
"multiple": {}}
return args
@ -35,7 +36,8 @@ def cache_apkindex(args, version):
"""
apkindex_path = list(args.cache["apkindex"].keys())[0]
providers = args.cache["apkindex"][apkindex_path]["multiple"]["hello-world"]
providers = args.cache[
"apkindex"][apkindex_path]["multiple"]["hello-world"]
providers["hello-world"]["version"] = version

View File

@ -235,7 +235,8 @@ def test_init_buildenv(args, monkeypatch):
# Shortcut and fake apkbuild
func = pmb.build._package.init_buildenv
apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["b"], "options": []}
apkbuild = {"pkgname": "test", "depends": ["a"], "makedepends": ["b"],
"options": []}
# Build is necessary (various code paths)
assert func(args, apkbuild, "armhf", strict=True) is True

View File

@ -8,7 +8,8 @@ import pmb.config
def test_chroot_interactive_shell():
"""
Open a shell with 'pmbootstrap chroot' and pass 'echo hello_world\n' as stdin.
Open a shell with 'pmbootstrap chroot' and pass 'echo hello_world\n' as
stdin.
"""
os.chdir(pmb.config.pmb_src)
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot", "sh"],
@ -24,7 +25,8 @@ def test_chroot_interactive_shell_user():
"""
os.chdir(pmb.config.pmb_src)
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot",
"--user", "sh"], timeout=300, input="id -un",
"--user", "sh"], timeout=300,
input="id -un",
universal_newlines=True,
stderr=subprocess.STDOUT)
assert ret == "pmos\n"
@ -32,15 +34,18 @@ def test_chroot_interactive_shell_user():
def test_chroot_arguments():
"""
Open a shell with 'pmbootstrap chroot' for every architecture, pass 'uname -m\n'
as stdin and check the output
Open a shell with 'pmbootstrap chroot' for every architecture, pass
'uname -m\n' as stdin and check the output
"""
os.chdir(pmb.config.pmb_src)
for arch in ["armhf", "aarch64", "x86_64"]:
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot", "-b", arch,
"sh"], timeout=300, input="uname -m\n",
universal_newlines=True, stderr=subprocess.STDOUT)
ret = subprocess.check_output(["./pmbootstrap.py", "-q", "chroot",
"-b", arch, "sh"],
timeout=300,
input="uname -m\n",
universal_newlines=True,
stderr=subprocess.STDOUT)
if arch == "armhf":
assert ret == "armv7l\n"
else:

View File

@ -23,8 +23,8 @@ def args(tmpdir, request):
def change_config(monkeypatch, path_config, key, value):
args = args_patched(monkeypatch, ["pmbootstrap.py", "-c", path_config, "config",
key, value])
args = args_patched(monkeypatch, ["pmbootstrap.py", "-c", path_config,
"config", key, value])
pmb.helpers.frontend.config(args)

View File

@ -25,9 +25,9 @@ def args(request):
def pmbootstrap(args, tmpdir, parameters, zero_exit=True):
"""
Helper function for running pmbootstrap inside the fake work folder (created
by setup() below) with the binary repo disabled and with the testdata
configured as aports.
Helper function for running pmbootstrap inside the fake work folder
(created by setup() below) with the binary repo disabled and with the
testdata configured as aports.
:param parameters: what to pass to pmbootstrap, e.g. ["build", "testlib"]
:param zero_exit: expect pmbootstrap to exit with 0 (no error)
@ -64,8 +64,8 @@ def setup_work(args, tmpdir):
well, so it can be modified during testing.
"""
# Clean the chroots, and initialize the build chroot in the native chroot.
# We do this before creating the fake work folder, because then all packages
# are still present.
# We do this before creating the fake work folder, because then all
# packages are still present.
os.chdir(pmb.config.pmb_src)
pmb.helpers.run.user(args, ["./pmbootstrap.py", "-y", "zap"])
pmb.helpers.run.user(args, ["./pmbootstrap.py", "build_init"])
@ -85,8 +85,9 @@ def setup_work(args, tmpdir):
f"{tmpdir}/_aports/device/testing"])
for pkgname in ["testlib", "testapp", "testsubpkg"]:
pmb.helpers.run.user(args, ["cp", "-r",
"test/testdata/pkgrel_bump/aports/" + pkgname,
tmpdir + "/_aports/main/" + pkgname])
"test/testdata/pkgrel_bump/aports/"
f"{pkgname}",
f"{tmpdir}/_aports/main/{pkgname}"])
# Copy pmaports.cfg
pmb.helpers.run.user(args, ["cp", args.aports + "/pmaports.cfg", tmpdir +

View File

@ -120,15 +120,15 @@ def is_running(args, programs, timeout=300, sleep_before_retry=1):
"""
Simple check that looks for program names in the output of "ps ax".
This is error-prone, only use it with programs that have a unique name.
With defaults timeout and sleep_before_retry values, it will try keep trying
for 5 minutes, but not more than once per second.
With defaults timeout and sleep_before_retry values, it will try keep
trying for 5 minutes, but not more than once per second.
:param programs: list of programs to check for, e.g. ["xfce4-desktop"]
:param timeout: approximate time in seconds until timeout
:param sleep_before_retry: time in seconds to sleep before trying again
"""
print("Looking for programs to appear in the VM (timeout: " + str(timeout) +
"): " + ", ".join(programs))
print(f"Looking for programs to appear in the VM (timeout: {timeout}): " +
", ".join(programs))
ssh_works = False
end = time.monotonic() + timeout
@ -170,7 +170,8 @@ def test_none(args, tmpdir, qemu):
# Check that at least SSH works (no special process running)
assert is_running(args, [])
# self-test of is_running() - invalid-process should not be detected as running
# self-test of is_running() - invalid-process should not be detected as
# running
assert is_running(args, ["invalid-process"], 1) is False
@ -181,7 +182,7 @@ def test_xfce4(args, tmpdir, qemu):
def test_plasma_mobile(args, tmpdir, qemu):
# NOTE: Once we have plasma mobile running properly without GL, we can check
# for more processes
# NOTE: Once we have plasma mobile running properly without GL, we can
# check for more processes
qemu.run(args, tmpdir, "plasma-mobile")
assert is_running(args, ["polkitd"])