Skip to content

Commit

Permalink
Improve linting tests
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <carmenbianca@fsfe.org>
  • Loading branch information
carmenbianca committed Oct 24, 2023
1 parent 6101a29 commit 4e3e78f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/reuse/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def format_plain(report: ProjectReport) -> str:
files_without_licenses_excl
)

if files_without_either:
if files_without_either or files_without_both:
header = (
"# " + _("MISSING COPYRIGHT AND LICENSING INFORMATION") + "\n\n"
)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ def test_lint_deprecated(fake_repository):
result = format_plain(report)

assert ":-(" in result
assert "# DEPRECATED LICENSES" in result
assert "GPL-3.0" in result
assert "Fix deprecated licenses:" in result
assert "spdx.org/licenses/#deprecated" in result


def test_lint_bad_license(fake_repository):
Expand All @@ -99,8 +102,26 @@ def test_lint_bad_license(fake_repository):
result = format_plain(report)

assert ":-(" in result
assert "# BAD LICENSES" in result
assert "foo.py" in result
assert "bad-license" in result
assert "Fix bad licenses:" in result
assert "reuse.software/faq/#custom-license" in result


def test_lint_licenses_without_extension(fake_repository):
"""A license without file extension is detected."""
(fake_repository / "LICENSES/GPL-3.0-or-later.txt").rename(
fake_repository / "LICENSES/GPL-3.0-or-later"
)
project = Project(fake_repository)
report = ProjectReport.generate(project)
result = format_plain(report)

assert ":-(" in result
assert "# LICENSES WITHOUT FILE EXTENSION" in result
assert "GPL-3.0-or-later" in result
assert "Fix licenses without file extension:" in result


def test_lint_missing_licenses(fake_repository):
Expand All @@ -111,8 +132,10 @@ def test_lint_missing_licenses(fake_repository):
result = format_plain(report)

assert ":-(" in result
assert "# MISSING LICENSES" in result
assert "foo.py" in result
assert "MIT" in result
assert "Fix missing licenses:" in result


def test_lint_unused_licenses(fake_repository):
Expand All @@ -123,7 +146,9 @@ def test_lint_unused_licenses(fake_repository):
result = format_plain(report)

assert ":-(" in result
assert "# UNUSED LICENSES" in result
assert "Unused licenses: MIT" in result
assert "Fix unused licenses:" in result


@cpython
Expand All @@ -137,8 +162,10 @@ def test_lint_read_errors(fake_repository):
result = format_plain(report)

assert ":-(" in result
assert "# READ ERRORS" in result
assert "Could not read:" in result
assert "foo.py" in result
assert "Fix read errors:" in result


def test_lint_files_without_copyright_and_licensing(fake_repository):
Expand All @@ -149,11 +176,14 @@ def test_lint_files_without_copyright_and_licensing(fake_repository):
result = format_plain(report)

assert ":-(" in result
assert "# MISSING COPYRIGHT AND LICENSING INFORMATION" in result
assert (
"The following files have no copyright and licensing information:"
in result
)
assert "foo.py" in result
assert "Fix missing copyright/licensing information:" in result
assert "reuse.software/tutorial" in result


def test_lint_json_output(fake_repository):
Expand All @@ -172,9 +202,11 @@ def test_lint_json_output(fake_repository):
assert "non_compliant" in json_result
assert "files" in json_result
assert "summary" in json_result
assert "recommendations" in json_result
# Test length of resulting list values
assert len(json_result["files"]) == 9
assert len(json_result["summary"]) == 5
assert len(json_result["recommendations"]) == 2
# Test result
assert json_result["summary"]["compliant"] is False
# Test license path
Expand Down

0 comments on commit 4e3e78f

Please sign in to comment.