diff options
Diffstat (limited to 'tests/test_build.py')
-rw-r--r-- | tests/test_build.py | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/tests/test_build.py b/tests/test_build.py index a30cff4..77b1898 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -582,49 +582,64 @@ def sample_source_error_missing_file(monkeypatch, sample_source): Modify index.json to expect missing report.spdx file and cause an error. """ monkeypatch.delitem(index_obj, 'reuse_generate_spdx_report') - return FileNotFoundError + return FileNotFoundError, @error_maker 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 + return ValidationError, @error_maker def sample_source_error_bad_comment(monkeypatch, sample_source): """Modify index.json to have an invalid '/' in it.""" - return json.JSONDecodeError, json.dumps(index_obj) + '/something\n' + return json.JSONDecodeError, '^bad_comment: .*', \ + json.dumps(index_obj) + '/something\n' @error_maker 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' + return json.JSONDecodeError, '', json.dumps(index_obj) + '???\n' @error_maker 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 + return build.ReuseError, '^couldnt_execute_reuse_is_it_installed$' @error_maker def sample_source_error_missing_license(monkeypatch, sample_source): """Remove a file to make package REUSE-incompliant.""" (sample_source / 'README.txt.license').unlink() - return build.ReuseError + + error_regex = """^\ +command_reuse --root \\S+ lint_failed + +STDOUT_OUTPUT_heading + +dummy lint output + +STDERR_OUTPUT_heading + +some error output\ +$\ +""" + + return build.ReuseError, error_regex @error_maker 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 + return FileReferenceError, '^path_contains_double_dot_\\.\\./abc$' @error_maker 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 + return FileReferenceError, '^loading_reserved_index_json$' @error_maker def sample_source_error_report_excluded(monkeypatch, sample_source): @@ -635,7 +650,7 @@ def sample_source_error_report_excluded(monkeypatch, sample_source): new_list = [file_ref for file_ref in index_obj['copyright'] if file_ref['file'] != 'report.spdx'] monkeypatch.setitem(index_obj, 'copyright', new_list) - return FileReferenceError + return FileReferenceError, '^report_spdx_not_in_copyright_list$' @pytest.fixture(params=error_makers) def sample_source_make_errors(request, monkeypatch, sample_source): @@ -644,10 +659,8 @@ def sample_source_make_errors(request, monkeypatch, sample_source): broken versions. Return an error type that should be raised when running test build. """ - index_text = None - error_type = request.param(monkeypatch, sample_source) - if type(error_type) is tuple: - error_type, index_text = error_type + error_type, error_regex, index_text = \ + [*request.param(monkeypatch, sample_source), '', ''][0:3] index_text = index_text or json.dumps(index_obj) @@ -655,13 +668,13 @@ def sample_source_make_errors(request, monkeypatch, sample_source): monkeypatch.setitem(src_files, 'index.json', index_text.encode()) - return error_type + return error_type, error_regex @pytest.mark.subprocess_run(build, run_reuse) @pytest.mark.usefixtures('mock_subprocess_run') def test_build_error(tmpdir, sample_source, sample_source_make_errors): """Try building the sample source package and verify generated errors.""" - error_type = sample_source_make_errors + error_type, error_regex = sample_source_make_errors dstdir = Path(tmpdir) / 'dstdir' tmpdir = Path(tmpdir) / 'example' @@ -669,6 +682,6 @@ def test_build_error(tmpdir, sample_source, sample_source_make_errors): dstdir.mkdir(exist_ok=True) tmpdir.mkdir(exist_ok=True) - with pytest.raises(error_type): + with pytest.raises(error_type, match=error_regex): build.Build(sample_source, Path('index.json'))\ .write_package_files(dstdir) |