diff --git a/.travis.yml b/.travis.yml index f3d9e6b3..2a5a739d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,11 +7,12 @@ addons: - debian-sid packages: - shellcheck -install: "pip install flake8" +install: "pip install flake8 pytest-cov" script: - test/static_code_analysis.sh - yes "" | ./pmbootstrap.py init - ./pmbootstrap.py kconfig_check + - test/testcases_fast.sh - test/check_checksums.py notifications: - email: false diff --git a/pmb/helpers/other.py b/pmb/helpers/other.py index 9eee8bb8..be23e888 100644 --- a/pmb/helpers/other.py +++ b/pmb/helpers/other.py @@ -26,11 +26,14 @@ import pmb.helpers.run def folder_size(args, path): """ Run `du` to calculate the size of a folder (this is less code and - faster than doing the same task in pure Python). + faster than doing the same task in pure Python). This result is only + approximatelly right, but good enough for pmbootstrap's use case: + :returns: folder size in bytes """ output = pmb.helpers.run.root(args, ["du", "--summarize", + "--apparent-size", "--block-size=1", path], return_stdout=True) ret = int(output.split("\t")[0]) diff --git a/test/static_code_analysis.sh b/test/static_code_analysis.sh index cafc65ec..39e2e357 100755 --- a/test/static_code_analysis.sh +++ b/test/static_code_analysis.sh @@ -23,6 +23,7 @@ DIR="$(cd "$(dirname "$0")" && pwd -P)" cd "$DIR"/.. sh_files=" ./test/static_code_analysis.sh + ./test/testcases_fast.sh ./aports/main/postmarketos-base/firmwareload.sh ./aports/main/postmarketos-mkinitfs/init.sh.in ./aports/main/postmarketos-mkinitfs/init_functions.sh diff --git a/test/test_challenge_apk.py b/test/test_challenge_apk.py index 27941c19..f1577aa8 100644 --- a/test/test_challenge_apk.py +++ b/test/test_challenge_apk.py @@ -60,7 +60,7 @@ def test_apk_challenge_contents_diff(args): # Second file apk_b = temp_path_outside + "/b.apk" - pmb.chroot.user(args, ["cp", "/etc/abuild.conf", temp_path + "/" + name]) + pmb.chroot.user(args, ["cp", "/etc/motd", temp_path + "/" + name]) pmb.chroot.user(args, ["tar", "-czf", "b.apk", name], working_dir=temp_path) diff --git a/test/test_folder_size.py b/test/test_folder_size.py index 5a54143a..f2559906 100644 --- a/test/test_folder_size.py +++ b/test/test_folder_size.py @@ -39,13 +39,19 @@ def args(request): def test_get_folder_size(args, tmpdir): - # Write five 2 KB files to tmpdir + # Write five 200 KB files to tmpdir tmpdir = str(tmpdir) files = 5 for i in range(files): pmb.helpers.run.user(args, ["dd", "if=/dev/zero", "of=" + tmpdir + "/" + str(i), "bs=1K", - "count=2", "conv=notrunc"]) + "count=200", "conv=notrunc"]) - # Check if the size is correct - assert pmb.helpers.other.folder_size(args, tmpdir) == 20480 + # Check if the size is correct. Unfortunately, the `du` call + # in pmb.helpers.other.folder_size is not very accurate, so we + # allow 10kb of tolerance (good enough for our use case): + # + tolerance = 10240 + size = 204800 * files + result = pmb.helpers.other.folder_size(args, tmpdir) + assert (result < size + tolerance and result > size - tolerance) diff --git a/test/test_repo.py b/test/test_repo.py index b0ef6cdd..4dae0b7a 100644 --- a/test/test_repo.py +++ b/test/test_repo.py @@ -21,7 +21,6 @@ import sys import pytest import types import time -import logging # Import from parent directory pmb_src = os.path.realpath(os.path.join(os.path.dirname(__file__) + "/..")) @@ -108,22 +107,3 @@ def test_hash(): url = "https://nl.alpinelinux.org/alpine/edge/testing" hash = "865a153c" assert pmb.helpers.repo.hash(url, 8) == hash - - -def test_apkindex_files(args): - # Make sure, that we have a user's APKINDEX.tar.gz - pmb.build.package(args, "hello-world", args.arch_native) - - # Reset the cache - del args.cache["apkindex_files"][args.arch_native] - - # Fake the upstream folder to be the same as the normal packages folder - args.mirror_postmarketos = args.work + "/packages" - - files = pmb.helpers.repo.apkindex_files(args) - for file in files: - assert os.path.exists(file) - logging.info(file) - - # Test cache - assert files == pmb.helpers.repo.apkindex_files(args) diff --git a/test/testcases_fast.sh b/test/testcases_fast.sh new file mode 100755 index 00000000..7defb1da --- /dev/null +++ b/test/testcases_fast.sh @@ -0,0 +1,27 @@ +#!/bin/sh -e + +# Disable slow testcases +# aport_in_sync_with_git: clones Alpine's aports repo +# aportgen: clones Alpine's aports repo +# build: builds cross-compilers for aarch64 and armhf +# version: clones Alpine's apk repo +disabled=" + aport_in_sync_with_git + aportgen + build + version +" + +# Filter out disabled testcases +enabled="" +cd "$(dirname "$0")/.." +for file in test/test_*.py; do + for test in $disabled; do + [ "test/test_${test}.py" = "$file" ] && continue 2 + done + enabled="$enabled $file" +done + +# Run enabled testcases with coverage enabled +# shellcheck disable=SC2086 +pytest --cov=pmb $enabled