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

Show on the map →

Called by none

Calls spdx_of

Checks

  • assert spdx_of("int x;\n") is None
  • assert spdx_of("\n" * 40 + "// SPDX-License-Identifier: MIT\n") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-008measuredtest_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
lines 41–41assert spdx_of("int x;\n") is Nonelines 42–42assert spdx_of("\n" * 40 + "// SPDX-License-Identifier: MIT\n") is None

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

Show on the map →

Called by none

Calls spdx_of

Checks

  • assert spdx_of(header)[0] == expression

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-008measuredtest_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
lines 33–33assert spdx_of(header)[0] == expression

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) == 1
  • assert rows == [("a.c", "MIT", 1)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_the_layer_records_each_file_and_exists_when_empty → ingest_file_licenses → license_of → memoized
REQ-DDB-INDEX-008measuredtest_the_layer_records_each_file_and_exists_when_empty → ingest_file_licenses
REQ-DDB-PIPE-014measuredtest_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

Activity · 13 steps
lines 47–47repo = tmp_path / "repo"lines 48–48repo.mkdir()lines 49–49(repo / "a.c").write_text("// SPDX-License-Identifier: MIT\nint a;\n")lines 50–50(repo / "b.py").write_text('"""No licence."""\n')lines 51–51db = tmp_path / "clew.db"lines 52–52conn = sqlite3.connect(db)lines 53–53conn.execute("CREATE TABLE path (rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER)")lines 54–54conn.executemany("INSERT INTO path(name, type) VALUES (?, 1)", [("a.c",), ("b.py",)])lines 55–55conn.commit()lines 56–56conn.close()lines 57–57assert ingest_file_licenses(db, repo) == 1lines 58–60rows = ( sqlite3.connect(db).execute("SELECT file_path, license, line FROM file_licenses").fetchall() )lines 61–61assert rows == [("a.c", "MIT", 1)]