aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conftest.py11
-rw-r--r--src/hydrilla/builder/local_apt.py8
-rw-r--r--tests/test_build.py12
-rw-r--r--tests/test_local_apt.py24
4 files changed, 33 insertions, 22 deletions
diff --git a/conftest.py b/conftest.py
index 65d13d5..e41a61d 100644
--- a/conftest.py
+++ b/conftest.py
@@ -9,6 +9,8 @@ from pathlib import Path
import pytest
import pkgutil
+from tempfile import TemporaryDirectory
+from typing import Iterable
here = Path(__file__).resolve().parent
sys.path.insert(0, str(here / 'src'))
@@ -67,3 +69,12 @@ def no_gettext(monkeypatch, request):
for module in modules_to_process:
if hasattr(module, '_'):
monkeypatch.setattr(module, '_', lambda message: message)
+
+@pytest.fixture
+def tmpdir() -> Iterable[Path]:
+ """
+ Provide test case with a temporary directory that will be automatically
+ deleted after the test.
+ """
+ with TemporaryDirectory() as tmpdir:
+ yield Path(tmpdir)
diff --git a/src/hydrilla/builder/local_apt.py b/src/hydrilla/builder/local_apt.py
index 1bdc347..3bec08b 100644
--- a/src/hydrilla/builder/local_apt.py
+++ b/src/hydrilla/builder/local_apt.py
@@ -286,7 +286,7 @@ def local_apt(list: SourcesList, keys: [str]) -> Iterable[Apt]:
yield setup_local_apt(td, list, keys)
def download_apt_packages(list: SourcesList, keys: [str], packages: [str],
- destination_dir: Path, with_deps=False) -> [str]:
+ destination_dir: Path, with_deps: bool) -> [str]:
"""
Set up a local APT, update it using the specified sources.list configuration
and use it to download the specified packages.
@@ -380,7 +380,11 @@ def piggybacked_system(piggyback_def: dict, foreign_packages: Optional[Path]) \
if foreign_packages is None:
archives = td / 'archives'
archives.mkdir()
+ else:
+ archives = foreign_packages / 'apt'
+ archives.mkdir(exist_ok=True)
+ if [*archives.glob('*.deb')] == []:
sources_list = SourcesList(piggyback_def.get('sources_list', []),
piggyback_def.get('distribution'))
packages = piggyback_def['packages']
@@ -397,8 +401,6 @@ def piggybacked_system(piggyback_def: dict, foreign_packages: Optional[Path]) \
destination_dir=archives,
with_deps=with_deps
)
- else:
- archives = foreign_packages / 'apt'
for deb in archives.glob('*.deb'):
command = ['dpkg-deb', '-x', str(deb), str(root)]
diff --git a/tests/test_build.py b/tests/test_build.py
index 3d564e3..968ac8d 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -176,15 +176,6 @@ expected_source_description = {
expected = [*expected_resources, expected_mapping, expected_source_description]
-@pytest.fixture
-def tmpdir() -> Iterable[str]:
- """
- Provide test case with a temporary directory that will be automatically
- deleted after the test.
- """
- with TemporaryDirectory() as tmpdir:
- yield Path(tmpdir)
-
def run_reuse(command, **kwargs):
"""
Instead of running a 'reuse' command, check if 'mock_reuse_missing' file
@@ -677,10 +668,7 @@ def test_build_error(tmpdir, sample_source, sample_source_make_errors):
error_type, error_regex = sample_source_make_errors
dstdir = Path(tmpdir) / 'dstdir'
- tmpdir = Path(tmpdir) / 'example'
-
dstdir.mkdir(exist_ok=True)
- tmpdir.mkdir(exist_ok=True)
with pytest.raises(error_type, match=error_regex):
build.Build(sample_source, Path('index.json'))\
diff --git a/tests/test_local_apt.py b/tests/test_local_apt.py
index edd47fa..f94ee37 100644
--- a/tests/test_local_apt.py
+++ b/tests/test_local_apt.py
@@ -341,7 +341,7 @@ def test_local_apt_download(mock_cache_dir):
destination.mkdir()
local_apt.download_apt_packages(sources_list, local_apt.default_keys,
- ['libjs-mathjax'], destination)
+ ['libjs-mathjax'], destination, False)
libjs_mathjax_path = destination / 'libjs-mathjax_0%3a2.7.9+dfsg-1_all.deb'
fonts_mathjax_path = destination / 'fonts-mathjax_0%3a2.7.9+dfsg-1_all.deb'
@@ -418,7 +418,7 @@ $\
with pytest.raises(local_apt.AptError, match=error_regex):
local_apt.download_apt_packages(sources_list, local_apt.default_keys,
- ['libjs-mathjax'], destination)
+ ['libjs-mathjax'], destination, False)
assert [*destination.iterdir()] == []
@@ -469,7 +469,7 @@ $\
with pytest.raises(local_apt.AptError, match=error_regex):
local_apt.download_apt_packages(sources_list, local_apt.default_keys,
- ['libjs-mathjax'], destination)
+ ['libjs-mathjax'], destination, False)
assert [*destination.iterdir()] == []
@@ -499,7 +499,7 @@ $\
with pytest.raises(local_apt.AptError, match=error_regex):
local_apt.download_apt_packages(sources_list, local_apt.default_keys,
- ['libjs-mathjax'], destination)
+ ['libjs-mathjax'], destination, False)
assert [*destination.iterdir()] == []
@@ -572,7 +572,8 @@ def mock_download_packages(monkeypatch):
'base_depends': True,
'identity': 'nabia',
'props': {'distribution': 'nabia', 'dependencies': False},
- 'all_keys': local_apt.default_keys
+ 'all_keys': local_apt.default_keys,
+ 'prepared_directory': False
},
{
'with_deps': True,
@@ -586,19 +587,22 @@ def mock_download_packages(monkeypatch):
'depend_on_base_packages': False
},
'all_keys': [*local_apt.default_keys, 'AB' * 20],
+ 'prepared_directory': True
}
])
@pytest.mark.usefixtures('mock_download_packages', 'mock_subprocess_run')
-def test_piggybacked_system_download(params):
+def test_piggybacked_system_download(params, tmpdir):
"""
Verify that the piggybacked_system() function properly downloads and unpacks
APT packages.
"""
+ foreign_packages_dir = tmpdir if params['prepared_directory'] else None
+
with local_apt.piggybacked_system({
'system': 'apt',
**params['props'],
'packages': ['some-bin-package', 'another-package=1.1-2']
- }, None) as piggybacked:
+ }, foreign_packages_dir) as piggybacked:
expected_depends = [{'identifier': 'apt-common-licenses'}] \
if params['base_depends'] else []
assert piggybacked.package_must_depend == expected_depends
@@ -626,6 +630,9 @@ def test_piggybacked_system_download(params):
else:
assert path.read_text() == f'dummy {path.name}'
+ if foreign_packages_dir is not None:
+ assert path.parent == foreign_packages_dir / 'apt'
+
license_files = {*piggybacked.package_license_files}
assert license_files == {
@@ -654,6 +661,9 @@ def test_piggybacked_system_download(params):
assert not root.exists()
+ if foreign_packages_dir:
+ assert [*tmpdir.iterdir()] == [tmpdir / 'apt']
+
@pytest.mark.subprocess_run(local_apt, run_dpkg_deb)
@pytest.mark.usefixtures('mock_subprocess_run')
def test_piggybacked_system_no_download():