Commit 3dc924a4 authored by Jakub Ružička's avatar Jakub Ružička
Browse files

Merge branch 'fixes' into 'master'

faster self tests and random fixes

See merge request !48
parents 05bd92f6 580fd599
Pipeline #80648 passed with stage
in 15 minutes and 32 seconds
......@@ -91,6 +91,9 @@ class ProjectCache:
if not entries:
return None
paths = list(map(entry2path_valid, entries))
if None in paths:
# invalid entry
return None
return paths
def delete(self, cache_name, key):
......
......@@ -38,7 +38,7 @@ SUPPORTED_DISTROS = [
RE_PKG_NAME = r'Source:\s*(\S+)'
# orbital regexp cannon to parse Build-Depends from debian/control
RE_BUILD_DEPENDS = (
r'(?:\n|\A)Build-Depends:[ \t]*' # no whitespace before
r'(?:\n|\A)Build-Depends(?:-Indep)?:[ \t]*' # no whitespace before
r'(?:\n[ \t]+)?' # optional leading newline with whitespace
r'((?:[^,\n]+)' # first build dep
r'(?:,(?:[ \t]*' # comma separator and optional whitespace
......@@ -302,12 +302,13 @@ def get_build_deps_from_control_(control_text):
"""
parse Build-Depends from debian control file contents
"""
m = re.search(RE_BUILD_DEPENDS, control_text)
m = re.findall(RE_BUILD_DEPENDS, control_text)
if not m:
msg = "unable to parse Build-Depends from control"
raise ex.ParsingFailed(msg=msg)
deps_raw = m.group(1)
deps = re.split(r'\s*,\s*', deps_raw)
deps = []
for deps_raw in m:
deps += re.split(r'\s*,\s*', deps_raw)
return deps
......
from pathlib import Path
import os
import pytest
import re
from apkg.util import test
......@@ -13,13 +14,16 @@ APKG_BASE_DIR = Path(__file__).parents[2]
# NOTE(py35): use tmp_path instead of tmpdir
# when py3.5 support is dropped
@pytest.fixture(scope="module")
def repo_path(tmpdir_factory):
tmpdir = tmpdir_factory.mktemp("apkg_test_repo_")
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
return repo_path
def test_import_command_modules():
"""
test importing individual apkg command modules
py3.5 compat prevents meaningful error handling on ImportError
in apkg.cli.run_command right now :(
"""
import apkg.commands.build # noqa
import apkg.commands.build_dep # noqa
......@@ -30,32 +34,58 @@ def test_import_command_modules():
import apkg.commands.status # noqa
def test_apkg_make_archive(tmpdir, capsys):
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
repo_dir = str(repo_path)
assert repo_dir.endswith('apkg')
with cd(repo_dir):
def test_apkg_make_archive_cache(repo_path, caplog):
with cd(repo_path):
cache_path = Path('pkg/.cache.json')
if cache_path.exists():
os.remove(str(cache_path))
# 1) run with --no-cache shouldn't create cache
assert apkg('make-archive', '--no-cache') == 0
assert not cache_path.exists()
# 2) normal run should create cache
assert apkg('make-archive') == 0
out, _ = capsys.readouterr()
# first stdout line should be resulting archive
assert re.match(r"pkg/archives/dev/apkg-.*\.tar\.gz", out)
assert cache_path.exists()
# 3) should reuse archive from previous run
assert apkg('make-archive') == 0
# 4) --no-cache shouldn't reuse cached archive
assert apkg('make-archive', '--no-cache') == 0
# helpers to parse cumulative log output
def is_relevant(r):
if 'made archive' in r.message:
return True
if 'reuse cached archive' in r.message:
return True
return False
def msg_head(r):
head, _, _ = r.message.partition(' ')
return head
# pick relevant log lines's heads
msgs = [msg_head(r) for r in caplog.records if is_relevant(r)]
def test_apkg_get_archive_manual(tmpdir, capsys):
# make sure cached archive was reused only when it should
assert msgs == [
'made', # 1) should create archive
'made', # 2) should create archive as 2) didn't cache it
'reuse', # 3) should reuse archive from 2)
'made', # 4) should create archive due to --no-cache
]
def test_apkg_get_archive_manual(repo_path, capsys):
VERSION = '0.0.2'
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
repo_dir = str(repo_path)
assert repo_dir.endswith('apkg')
with cd(repo_dir):
with cd(repo_path):
assert apkg('get-archive', '--version', VERSION) == 0
out, _ = capsys.readouterr()
# first stdout line should be downloaded archive
assert out.startswith("pkg/archives/upstream/apkg-%s.tar.gz" % VERSION)
def test_apkg_get_archive_auto(tmpdir, capsys):
def test_apkg_get_archive_auto(repo_path, capsys):
# this tests upstream version detection as well
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
with cd(repo_path):
assert apkg('get-archive') == 0
out, _ = capsys.readouterr()
......@@ -63,22 +93,16 @@ def test_apkg_get_archive_auto(tmpdir, capsys):
assert out.startswith("pkg/archives/upstream/apkg-")
def test_apkg_srcpkg(tmpdir, capsys):
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
repo_dir = str(repo_path)
assert repo_dir.endswith('apkg')
with cd(repo_dir):
def test_apkg_srcpkg(repo_path, capsys):
with cd(repo_path):
assert apkg('srcpkg') == 0
out, _ = capsys.readouterr()
# first stdout line should be resulting source package
assert re.match(r"pkg/srcpkgs/\S+/apkg\S+", out)
def test_apkg_build(tmpdir, capsys):
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
repo_dir = str(repo_path)
assert repo_dir.endswith('apkg')
with cd(repo_dir):
def test_apkg_build(repo_path, capsys):
with cd(repo_path):
assert apkg('build') == 0
out, _ = capsys.readouterr()
# at least one package should be printed
......@@ -93,63 +117,19 @@ def assert_build_deps(deps_text):
assert False, "no python build dep detected"
def test_apkg_build_dep_tempalte(tmpdir, capsys):
def test_apkg_build_dep_tempalte(repo_path, capsys):
# check listing build deps from tempalte works
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
with cd(repo_path):
assert apkg('build-dep', '-l') == 0
out, _ = capsys.readouterr()
assert_build_deps(out)
def test_apkg_build_dep_srcpkg(tmpdir, capsys):
def test_apkg_build_dep_srcpkg(repo_path, capsys):
# check listing build deps from srcpkg works
# this includes srcpkg dev build
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
with cd(repo_path):
assert apkg('build-dep', '-s', '-l') == 0
out, _ = capsys.readouterr()
# check for a common build dep
assert_build_deps(out)
def test_apkg_cache(tmpdir, caplog):
repo_path = test.init_testing_repo(APKG_BASE_DIR, str(tmpdir))
with cd(repo_path):
cache_path = Path('pkg/.cache.json')
if cache_path.exists():
os.remove(str(cache_path))
# 1) run with --no-cache shouldn't create cache
assert apkg('make-archive', '--no-cache') == 0
assert not cache_path.exists()
# 2) normal run should create cache
assert apkg('make-archive') == 0
assert cache_path.exists()
# 3) should reuse archive from previous run
assert apkg('make-archive') == 0
# 4) --no-cache shouldn't reuse cached archive
assert apkg('make-archive', '--no-cache') == 0
# helpers to parse cumulative log output
def is_relevant(r):
if 'made archive' in r.message:
return True
if 'reuse cached archive' in r.message:
return True
return False
def msg_head(r):
head, _, _ = r.message.partition(' ')
return head
# pick relevant log lines's heads
msgs = [msg_head(r) for r in caplog.records if is_relevant(r)]
# make sure cached archive was reused only when it should
assert msgs == [
'made', # 1) should create archive
'made', # 2) should create archive as 2) didn't cache it
'reuse', # 3) should reuse archive from 2)
'made', # 4) should create archive due to --no-cache
]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment