summaryrefslogtreecommitdiff
path: root/tests/test_build.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_build.py')
-rw-r--r--tests/test_build.py116
1 files changed, 63 insertions, 53 deletions
diff --git a/tests/test_build.py b/tests/test_build.py
index 7fedbd5..0d3e662 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -10,6 +10,7 @@ from __future__ import annotations
import pytest
import json
import shutil
+import functools as ft
from tempfile import TemporaryDirectory
from pathlib import Path, PurePosixPath
@@ -255,13 +256,18 @@ def sample_source():
yield sample_source
+def collect(list):
+ """Decorate function by appending it to the specified list."""
+ def decorator(function):
+ """The actual decorator that will be applied."""
+ list.append(function)
+ return function
+
+ return decorator
+
variant_makers = []
-def variant_maker(function):
- """Decorate function by placing it in variant_makers array."""
- variant_makers.append(function)
- return function
-@variant_maker
+@collect(variant_makers)
def sample_source_change_index_json(monkeypatch, sample_source):
"""
Return a non-standard path for index.json. Ensure parent directories exist.
@@ -272,13 +278,13 @@ def sample_source_change_index_json(monkeypatch, sample_source):
path.parent.mkdir()
return path
-@variant_maker
+@collect(variant_makers)
def sample_source_add_comments(monkeypatch, sample_source):
"""Add index.json comments that should be preserved."""
for dictionary in index_obj, *index_obj['definitions'], *expected:
monkeypatch.setitem(dictionary, 'comment', 'index.json comment')
-@variant_maker
+@collect(variant_makers)
def sample_source_remove_spdx(monkeypatch, sample_source):
"""Remove spdx report generation."""
monkeypatch.delitem(index_obj, 'reuse_generate_spdx_report')
@@ -297,7 +303,7 @@ def sample_source_remove_spdx(monkeypatch, sample_source):
# raise an error if called.
(sample_source / 'mock_reuse_missing').touch()
-@variant_maker
+@collect(variant_makers)
def sample_source_remove_additional_files(monkeypatch, sample_source):
"""Use default value ([]) for 'additionall_files' property."""
monkeypatch.delitem(index_obj, 'additional_files')
@@ -305,7 +311,7 @@ def sample_source_remove_additional_files(monkeypatch, sample_source):
for name in 'README.txt', 'README.txt.license', '.reuse/dep5':
monkeypatch.delitem(src_files, name)
-@variant_maker
+@collect(variant_makers)
def sample_source_remove_script(monkeypatch, sample_source):
"""Use default value ([]) for 'scripts' property in one of the resources."""
monkeypatch.delitem(index_obj['definitions'][2], 'scripts')
@@ -315,14 +321,14 @@ def sample_source_remove_script(monkeypatch, sample_source):
for files in dist_files, src_files:
monkeypatch.delitem(files, 'message.js')
-@variant_maker
+@collect(variant_makers)
def sample_source_remove_payloads(monkeypatch, sample_source):
"""Use default value ({}) for 'payloads' property in mapping."""
monkeypatch.delitem(index_obj['definitions'][0], 'payloads')
monkeypatch.setitem(expected_mapping, 'payloads', {})
-@variant_maker
+@collect(variant_makers)
def sample_source_remove_uuids(monkeypatch, sample_source):
"""Don't use UUIDs (they are optional)."""
for definition in index_obj['definitions']:
@@ -332,7 +338,7 @@ def sample_source_remove_uuids(monkeypatch, sample_source):
if 'uuid' in description:
monkeypatch.delitem(description, 'uuid')
-@variant_maker
+@collect(variant_makers)
def sample_source_add_extra_props(monkeypatch, sample_source):
"""Add some unrecognized properties that should be stripped."""
to_process = [index_obj]
@@ -346,41 +352,48 @@ def sample_source_add_extra_props(monkeypatch, sample_source):
if k != 'payloads')
monkeypatch.setitem(processed, 'spurious_property', 'some_value')
-@variant_maker
+@collect(variant_makers)
def sample_source_make_version_2(monkeypatch, sample_source,
expected_documents_to_modify=[]):
- """Increase sources' schema version from to 2."""
+ """Increase sources' schema version from 1 to 2."""
for obj in index_obj, *expected_documents_to_modify:
monkeypatch.setitem(obj, '$schema', obj['$schema'].replace('1', '2'))
-@variant_maker
-def sample_source_cors_bypass_ignored(monkeypatch, sample_source, value=True):
+permission_variant_makers = []
+
+@collect(permission_variant_makers)
+def sample_source_bool_perm_ignored(permission, monkeypatch, sample_source,
+ value=True):
"""
- Specify CORS bypass permissions in sources, but keep sources' schema version
+ Specify a boolean permissions in sources, but keep sources' schema version
at 1.
"""
for definition in index_obj['definitions']:
- monkeypatch.setitem(definition, 'permissions', {'cors_bypass': value})
+ monkeypatch.setitem(definition, 'permissions', {permission: value})
-@variant_maker
-def sample_source_cors_bypass(monkeypatch, sample_source):
- """Specify CORS bypass permissions in sources."""
- sample_source_cors_bypass_ignored(monkeypatch, sample_source, value=True)
+@collect(permission_variant_makers)
+def sample_source_bool_perm(permission, monkeypatch, sample_source):
+ """Specify a boolean permission in sources."""
+ sample_source_bool_perm_ignored(permission, monkeypatch, sample_source)
sample_source_make_version_2(monkeypatch, sample_source, expected_items)
for obj in expected_items:
- monkeypatch.setitem(obj, 'permissions', {'cors_bypass': True})
+ monkeypatch.setitem(obj, 'permissions', {permission: True})
-@variant_maker
-def sample_source_cors_bypass_defaults(monkeypatch, sample_source):
+@collect(permission_variant_makers)
+def sample_source_bool_perm_defaults(permission, monkeypatch, sample_source):
"""
- Specify CORS bypass permissions in sources but use the default value
- ("False").
+ Specify a boolean permission in sources but use the default value ("False").
"""
- sample_source_cors_bypass_ignored(monkeypatch, sample_source, value=False)
+ sample_source_bool_perm_ignored(permission, monkeypatch, sample_source,
+ value=False)
sample_source_make_version_2(monkeypatch, sample_source)
-@variant_maker
+for permission in 'cors_bypass', 'eval':
+ for variant_maker in permission_variant_makers:
+ variant_makers.append(ft.partial(variant_maker, permission))
+
+@collect(variant_makers)
def sample_source_req_mappings_ignored(monkeypatch, sample_source,
value=[{'identifier': 'mapping-dep'}]):
"""
@@ -389,7 +402,7 @@ def sample_source_req_mappings_ignored(monkeypatch, sample_source,
for definition in index_obj['definitions']:
monkeypatch.setitem(definition, 'required_mappings', value);
-@variant_maker
+@collect(variant_makers)
def sample_source_req_mappings(monkeypatch, sample_source):
"""Specify dependencies on mappings."""
sample_source_req_mappings_ignored(monkeypatch, sample_source)
@@ -399,13 +412,13 @@ def sample_source_req_mappings(monkeypatch, sample_source):
monkeypatch.setitem(obj, 'required_mappings',
[{'identifier': 'mapping-dep'}])
-@variant_maker
+@collect(variant_makers)
def sample_source_req_mappings_defaults(monkeypatch, sample_source):
"""Specify dependencies of a mapping, but use the default value ("[]")."""
sample_source_req_mappings_ignored(monkeypatch, sample_source, value=[])
sample_source_make_version_2(monkeypatch, sample_source)
-@variant_maker
+@collect(variant_makers)
def sample_source_combined_def(monkeypatch, sample_source):
"""Define mapping and resource together."""
sample_source_make_version_2(monkeypatch, sample_source)
@@ -432,7 +445,7 @@ def sample_source_combined_def(monkeypatch, sample_source):
monkeypatch.setitem(expected_source_description['definitions'][0],
'version', new_mapping_ver)
-@variant_maker
+@collect(variant_makers)
def sample_source_minmax_haketilo_ver_ignored(monkeypatch, sample_source,
min_ver=[1, 2], max_ver=[1, 2]):
"""
@@ -443,7 +456,7 @@ def sample_source_minmax_haketilo_ver_ignored(monkeypatch, sample_source,
monkeypatch.setitem(mapping_def, 'min_haketilo_version', min_ver)
monkeypatch.setitem(mapping_def, 'max_haketilo_version', max_ver)
-@variant_maker
+@collect(variant_makers)
def sample_source_minmax_haketilo_ver(monkeypatch, sample_source):
"""Specify version constraints on Haketilo."""
sample_source_minmax_haketilo_ver_ignored(monkeypatch, sample_source)
@@ -452,7 +465,7 @@ def sample_source_minmax_haketilo_ver(monkeypatch, sample_source):
monkeypatch.setitem(expected_mapping, 'min_haketilo_version', [1, 2])
monkeypatch.setitem(expected_mapping, 'max_haketilo_version', [1, 2])
-@variant_maker
+@collect(variant_makers)
def sample_source_minmax_haketilo_ver_default(monkeypatch, sample_source):
"""Specify version constraints on Haketilo, but use default values."""
sample_source_minmax_haketilo_ver_ignored(monkeypatch, sample_source,
@@ -466,7 +479,7 @@ piggyback_archive_names = [
'othersystem/other-something.tar.gz'
]
-@variant_maker
+@collect(variant_makers)
def sample_source_add_piggyback_ignored(monkeypatch, sample_source,
extra_build_args={}):
"""
@@ -484,7 +497,7 @@ def sample_source_add_piggyback_ignored(monkeypatch, sample_source,
'dependencies': False
})
-@variant_maker
+@collect(variant_makers)
def sample_source_add_piggyback(monkeypatch, sample_source,
extra_build_args={}):
"""Add piggybacked foreign system packages."""
@@ -528,7 +541,7 @@ def prepare_foreign_packages_dir(path):
archive_path.parent.mkdir(parents=True, exist_ok=True)
archive_path.write_text(f'dummy {archive_path.name}')
-@variant_maker
+@collect(variant_makers)
def sample_source_add_piggyback_pass_archives(monkeypatch, sample_source):
"""
Add piggybacked foreign system packages, use pre-downloaded foreign package
@@ -542,7 +555,7 @@ def sample_source_add_piggyback_pass_archives(monkeypatch, sample_source):
sample_source_add_piggyback(monkeypatch, sample_source,
{'piggyback_files': foreign_packages_dir})
-@variant_maker
+@collect(variant_makers)
def sample_source_add_piggyback_find_archives(monkeypatch, sample_source):
"""
Add piggybacked foreign system packages, use pre-downloaded foreign package
@@ -555,7 +568,7 @@ def sample_source_add_piggyback_find_archives(monkeypatch, sample_source):
sample_source_add_piggyback(monkeypatch, sample_source)
-@variant_maker
+@collect(variant_makers)
def sample_source_add_piggyback_no_download(monkeypatch, sample_source,
pass_directory_to_build=False):
"""
@@ -678,11 +691,8 @@ def test_build(sample_source, sample_source_make_variants, tmpdir):
try_validate('api_source_description', expected_source_description)
error_makers = []
-def error_maker(function):
- """Decorate function by placing it in error_makers array."""
- error_makers.append(function)
-@error_maker
+@collect(error_makers)
def sample_source_error_missing_file(monkeypatch, sample_source):
"""
Modify index.json to expect missing report.spdx file and cause an error.
@@ -690,30 +700,30 @@ def sample_source_error_missing_file(monkeypatch, sample_source):
monkeypatch.delitem(index_obj, 'reuse_generate_spdx_report')
return FileReferenceError, '^referenced_file_report.spdx_missing$'
-@error_maker
+@collect(error_makers)
def sample_source_error_index_schema(monkeypatch, sample_source):
"""Modify index.json to be incompliant with the schema."""
monkeypatch.delitem(index_obj, 'definitions')
return ValidationError,
-@error_maker
+@collect(error_makers)
def sample_source_error_bad_comment(monkeypatch, sample_source):
"""Modify index.json to have an invalid '/' in it."""
return json.JSONDecodeError, '^bad_comment: .*', \
json.dumps(index_obj) + '/something\n'
-@error_maker
+@collect(error_makers)
def sample_source_error_bad_json(monkeypatch, sample_source):
"""Modify index.json to not be valid json even after comment stripping."""
return json.JSONDecodeError, '', json.dumps(index_obj) + '???\n'
-@error_maker
+@collect(error_makers)
def sample_source_error_missing_reuse(monkeypatch, sample_source):
"""Cause mocked reuse process invocation to fail with FileNotFoundError."""
(sample_source / 'mock_reuse_missing').touch()
return build.ReuseError, '^couldnt_execute_reuse_is_it_installed$'
-@error_maker
+@collect(error_makers)
def sample_source_error_missing_license(monkeypatch, sample_source):
"""Remove a file to make package REUSE-incompliant."""
(sample_source / 'README.txt.license').unlink()
@@ -733,21 +743,21 @@ $\
return build.ReuseError, error_regex
-@error_maker
+@collect(error_makers)
def sample_source_error_file_outside(monkeypatch, sample_source):
"""Make index.json illegally reference a file outside srcdir."""
new_list = [*index_obj['copyright'], {'file': '../abc'}]
monkeypatch.setitem(index_obj, 'copyright', new_list)
return FileReferenceError, '^path_contains_double_dot_\\.\\./abc$'
-@error_maker
+@collect(error_makers)
def sample_source_error_reference_itself(monkeypatch, sample_source):
"""Make index.json illegally reference index.json."""
new_list = [*index_obj['copyright'], {'file': 'index.json'}]
monkeypatch.setitem(index_obj, 'copyright', new_list)
return FileReferenceError, '^loading_reserved_index_json$'
-@error_maker
+@collect(error_makers)
def sample_source_error_report_excluded(monkeypatch, sample_source):
"""
Make index.json require generation of report.spdx but don't include it among
@@ -758,7 +768,7 @@ def sample_source_error_report_excluded(monkeypatch, sample_source):
monkeypatch.setitem(index_obj, 'copyright', new_list)
return FileReferenceError, '^report_spdx_not_in_copyright_list$'
-@error_maker
+@collect(error_makers)
def sample_source_error_combined_unsupported(monkeypatch, sample_source):
"""
Define mapping and resource together but leave source schema version at 1.x