test_file_licenses.py¶
tests/test_file_licenses.py
Each file's `SPDX-License-Identifier` header is recorded, not skipped (S5; 2.0.0).
test_no_tag_and_a_tag_far_below_the_header_are_not_declarations
None test_file_licenses.test_no_tag_and_a_tag_far_below_the_header_are_not_declarations()
Only the header declares.
tests/test_file_licenses.py:36
Checks
assert spdx_of("int x;\n") is Noneassert spdx_of("\n" * 40 + "// SPDX-License-Identifier: MIT\n") is None
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-008 | measured | test_no_tag_and_a_tag_far_below_the_header_are_not_declarations → spdx_of |
Source · 9 lines
def test_no_tag_and_a_tag_far_below_the_header_are_not_declarations() -> None:
"""REUSE places the tag in the header; a mention deep in a file is prose, not a declaration.
@brief Only the header declares.
"""
assert spdx_of("int x;\n") is None
assert spdx_of("\n" * 40 + "// SPDX-License-Identifier: MIT\n") is None
Activity · 2 steps
test_the_expression_is_read_in_any_comment_style
None test_file_licenses.test_the_expression_is_read_in_any_comment_style(str header, str expression)
The tag is matched where it stands, whatever opens the comment.
tests/test_file_licenses.py:31
Checks
assert spdx_of(header)[0] == expression
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-008 | measured | test_the_expression_is_read_in_any_comment_style → spdx_of |
Source · 5 lines
def test_the_expression_is_read_in_any_comment_style(header: str, expression: str) -> None:
"""@brief The tag is matched where it stands, whatever opens the comment."""
assert spdx_of(header)[0] == expression
Activity · 1 steps
test_the_layer_records_each_file_and_exists_when_empty
None test_file_licenses.test_the_layer_records_each_file_and_exists_when_empty(Path tmp_path)
One row per declaring file; the table is created even with none.
tests/test_file_licenses.py:45
Checks
assert ingest_file_licenses(db, repo) == 1assert rows == [("a.c", "MIT", 1)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_the_layer_records_each_file_and_exists_when_empty → ingest_file_licenses → license_of → memoized |
| REQ-DDB-INDEX-008 | measured | test_the_layer_records_each_file_and_exists_when_empty → ingest_file_licenses |
| REQ-DDB-PIPE-014 | measured | test_the_layer_records_each_file_and_exists_when_empty → ingest_file_licenses → within_repo |
Source · 17 lines
def test_the_layer_records_each_file_and_exists_when_empty(tmp_path: Path) -> None:
"""@brief One row per declaring file; the table is created even with none."""
repo = tmp_path / "repo"
repo.mkdir()
(repo / "a.c").write_text("// SPDX-License-Identifier: MIT\nint a;\n")
(repo / "b.py").write_text('"""No licence."""\n')
db = tmp_path / "clew.db"
conn = sqlite3.connect(db)
conn.execute("CREATE TABLE path (rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER)")
conn.executemany("INSERT INTO path(name, type) VALUES (?, 1)", [("a.c",), ("b.py",)])
conn.commit()
conn.close()
assert ingest_file_licenses(db, repo) == 1
rows = (
sqlite3.connect(db).execute("SELECT file_path, license, line FROM file_licenses").fetchall()
)
assert rows == [("a.c", "MIT", 1)]1 more lines, not shown