Revision 496d90f7
Added by koszko over 1 year ago
conftest.py | ||
---|---|---|
9 | 9 |
|
10 | 10 |
import pytest |
11 | 11 |
import pkgutil |
12 |
from tempfile import TemporaryDirectory |
|
13 |
from typing import Iterable |
|
12 | 14 |
|
13 | 15 |
here = Path(__file__).resolve().parent |
14 | 16 |
sys.path.insert(0, str(here / 'src')) |
... | ... | |
67 | 69 |
for module in modules_to_process: |
68 | 70 |
if hasattr(module, '_'): |
69 | 71 |
monkeypatch.setattr(module, '_', lambda message: message) |
72 |
|
|
73 |
@pytest.fixture |
|
74 |
def tmpdir() -> Iterable[Path]: |
|
75 |
""" |
|
76 |
Provide test case with a temporary directory that will be automatically |
|
77 |
deleted after the test. |
|
78 |
""" |
|
79 |
with TemporaryDirectory() as tmpdir: |
|
80 |
yield Path(tmpdir) |
src/hydrilla/builder/local_apt.py | ||
---|---|---|
286 | 286 |
yield setup_local_apt(td, list, keys) |
287 | 287 |
|
288 | 288 |
def download_apt_packages(list: SourcesList, keys: [str], packages: [str], |
289 |
destination_dir: Path, with_deps=False) -> [str]:
|
|
289 |
destination_dir: Path, with_deps: bool) -> [str]:
|
|
290 | 290 |
""" |
291 | 291 |
Set up a local APT, update it using the specified sources.list configuration |
292 | 292 |
and use it to download the specified packages. |
... | ... | |
380 | 380 |
if foreign_packages is None: |
381 | 381 |
archives = td / 'archives' |
382 | 382 |
archives.mkdir() |
383 |
else: |
|
384 |
archives = foreign_packages / 'apt' |
|
385 |
archives.mkdir(exist_ok=True) |
|
383 | 386 |
|
387 |
if [*archives.glob('*.deb')] == []: |
|
384 | 388 |
sources_list = SourcesList(piggyback_def.get('sources_list', []), |
385 | 389 |
piggyback_def.get('distribution')) |
386 | 390 |
packages = piggyback_def['packages'] |
... | ... | |
397 | 401 |
destination_dir=archives, |
398 | 402 |
with_deps=with_deps |
399 | 403 |
) |
400 |
else: |
|
401 |
archives = foreign_packages / 'apt' |
|
402 | 404 |
|
403 | 405 |
for deb in archives.glob('*.deb'): |
404 | 406 |
command = ['dpkg-deb', '-x', str(deb), str(root)] |
tests/test_build.py | ||
---|---|---|
176 | 176 |
|
177 | 177 |
expected = [*expected_resources, expected_mapping, expected_source_description] |
178 | 178 |
|
179 |
@pytest.fixture |
|
180 |
def tmpdir() -> Iterable[str]: |
|
181 |
""" |
|
182 |
Provide test case with a temporary directory that will be automatically |
|
183 |
deleted after the test. |
|
184 |
""" |
|
185 |
with TemporaryDirectory() as tmpdir: |
|
186 |
yield Path(tmpdir) |
|
187 |
|
|
188 | 179 |
def run_reuse(command, **kwargs): |
189 | 180 |
""" |
190 | 181 |
Instead of running a 'reuse' command, check if 'mock_reuse_missing' file |
... | ... | |
677 | 668 |
error_type, error_regex = sample_source_make_errors |
678 | 669 |
|
679 | 670 |
dstdir = Path(tmpdir) / 'dstdir' |
680 |
tmpdir = Path(tmpdir) / 'example' |
|
681 |
|
|
682 | 671 |
dstdir.mkdir(exist_ok=True) |
683 |
tmpdir.mkdir(exist_ok=True) |
|
684 | 672 |
|
685 | 673 |
with pytest.raises(error_type, match=error_regex): |
686 | 674 |
build.Build(sample_source, Path('index.json'))\ |
tests/test_local_apt.py | ||
---|---|---|
341 | 341 |
destination.mkdir() |
342 | 342 |
|
343 | 343 |
local_apt.download_apt_packages(sources_list, local_apt.default_keys, |
344 |
['libjs-mathjax'], destination) |
|
344 |
['libjs-mathjax'], destination, False)
|
|
345 | 345 |
|
346 | 346 |
libjs_mathjax_path = destination / 'libjs-mathjax_0%3a2.7.9+dfsg-1_all.deb' |
347 | 347 |
fonts_mathjax_path = destination / 'fonts-mathjax_0%3a2.7.9+dfsg-1_all.deb' |
... | ... | |
418 | 418 |
|
419 | 419 |
with pytest.raises(local_apt.AptError, match=error_regex): |
420 | 420 |
local_apt.download_apt_packages(sources_list, local_apt.default_keys, |
421 |
['libjs-mathjax'], destination) |
|
421 |
['libjs-mathjax'], destination, False)
|
|
422 | 422 |
|
423 | 423 |
assert [*destination.iterdir()] == [] |
424 | 424 |
|
... | ... | |
469 | 469 |
|
470 | 470 |
with pytest.raises(local_apt.AptError, match=error_regex): |
471 | 471 |
local_apt.download_apt_packages(sources_list, local_apt.default_keys, |
472 |
['libjs-mathjax'], destination) |
|
472 |
['libjs-mathjax'], destination, False)
|
|
473 | 473 |
|
474 | 474 |
assert [*destination.iterdir()] == [] |
475 | 475 |
|
... | ... | |
499 | 499 |
|
500 | 500 |
with pytest.raises(local_apt.AptError, match=error_regex): |
501 | 501 |
local_apt.download_apt_packages(sources_list, local_apt.default_keys, |
502 |
['libjs-mathjax'], destination) |
|
502 |
['libjs-mathjax'], destination, False)
|
|
503 | 503 |
|
504 | 504 |
assert [*destination.iterdir()] == [] |
505 | 505 |
|
... | ... | |
572 | 572 |
'base_depends': True, |
573 | 573 |
'identity': 'nabia', |
574 | 574 |
'props': {'distribution': 'nabia', 'dependencies': False}, |
575 |
'all_keys': local_apt.default_keys |
|
575 |
'all_keys': local_apt.default_keys, |
|
576 |
'prepared_directory': False |
|
576 | 577 |
}, |
577 | 578 |
{ |
578 | 579 |
'with_deps': True, |
... | ... | |
586 | 587 |
'depend_on_base_packages': False |
587 | 588 |
}, |
588 | 589 |
'all_keys': [*local_apt.default_keys, 'AB' * 20], |
590 |
'prepared_directory': True |
|
589 | 591 |
} |
590 | 592 |
]) |
591 | 593 |
@pytest.mark.usefixtures('mock_download_packages', 'mock_subprocess_run') |
592 |
def test_piggybacked_system_download(params): |
|
594 |
def test_piggybacked_system_download(params, tmpdir):
|
|
593 | 595 |
""" |
594 | 596 |
Verify that the piggybacked_system() function properly downloads and unpacks |
595 | 597 |
APT packages. |
596 | 598 |
""" |
599 |
foreign_packages_dir = tmpdir if params['prepared_directory'] else None |
|
600 |
|
|
597 | 601 |
with local_apt.piggybacked_system({ |
598 | 602 |
'system': 'apt', |
599 | 603 |
**params['props'], |
600 | 604 |
'packages': ['some-bin-package', 'another-package=1.1-2'] |
601 |
}, None) as piggybacked:
|
|
605 |
}, foreign_packages_dir) as piggybacked:
|
|
602 | 606 |
expected_depends = [{'identifier': 'apt-common-licenses'}] \ |
603 | 607 |
if params['base_depends'] else [] |
604 | 608 |
assert piggybacked.package_must_depend == expected_depends |
... | ... | |
626 | 630 |
else: |
627 | 631 |
assert path.read_text() == f'dummy {path.name}' |
628 | 632 |
|
633 |
if foreign_packages_dir is not None: |
|
634 |
assert path.parent == foreign_packages_dir / 'apt' |
|
635 |
|
|
629 | 636 |
license_files = {*piggybacked.package_license_files} |
630 | 637 |
|
631 | 638 |
assert license_files == { |
... | ... | |
654 | 661 |
|
655 | 662 |
assert not root.exists() |
656 | 663 |
|
664 |
if foreign_packages_dir: |
|
665 |
assert [*tmpdir.iterdir()] == [tmpdir / 'apt'] |
|
666 |
|
|
657 | 667 |
@pytest.mark.subprocess_run(local_apt, run_dpkg_deb) |
658 | 668 |
@pytest.mark.usefixtures('mock_subprocess_run') |
659 | 669 |
def test_piggybacked_system_no_download(): |
Also available in: Unified diff
make it easier to reuse/cache foreign package files when building a Hydrilla source package multiple times