test_owners.py¶
tests/test_owners.py
Who owns a file, read from the repository's own CODEOWNERS and MAINTAINERS (S2, S3; 2.0.0).
test_a_declared_owners_file_is_read_and_a_missing_one_is_not_replaced
None test_owners.test_a_declared_owners_file_is_read_and_a_missing_one_is_not_replaced(Path tmp_path)
`owners.codeowners` wins; a declared path that is not a file reads nothing.
Checks
assert conn.execute("SELECT owner FROM owners").fetchall() == [("@meta",)]assert conn.execute("SELECT count(*) FROM owners").fetchone() == (0,)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | measured | test_a_declared_owners_file_is_read_and_a_missing_one_is_not_replaced → record_owners |
| REQ-DDB-PIPE-014 | measured |
Source · 13 lines
def test_a_declared_owners_file_is_read_and_a_missing_one_is_not_replaced(tmp_path: Path) -> None:
"""@brief `owners.codeowners` wins; a declared path that is not a file reads nothing."""
repo = _index(
tmp_path,
{"CODEOWNERS": "* @root\n", "meta/OWNERS": "* @meta\n", "src/a.c": "int a;\n"},
)
conn = sqlite3.connect(tmp_path / "clew.db")
record_owners(conn, repo, {"codeowners": "meta/OWNERS"})
assert conn.execute("SELECT owner FROM owners").fetchall() == [("@meta",)]
record_owners(conn, repo, {"codeowners": "missing/OWNERS"})
assert conn.execute("SELECT count(*) FROM owners").fetchone() == (0,)
Activity · 6 steps
test_a_rule_with_no_owners_unsets_ownership
None test_owners.test_a_rule_with_no_owners_unsets_ownership()
A later ownerless rule leaves the path unowned (GitHub's documented meaning).
Checks
assert codeowners_for(rules, "vendor/lib.c") == ([], 2)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | catalog |
Source · 6 lines
def test_a_rule_with_no_owners_unsets_ownership() -> None:
"""@brief A later ownerless rule leaves the path unowned (GitHub's documented meaning)."""
rules = parse_codeowners("* @all\n/vendor/\n")
assert codeowners_for(rules, "vendor/lib.c") == ([], 2)
Activity · 2 steps
test_codeowners_last_match_wins_with_all_its_owners
None test_owners.test_codeowners_last_match_wins_with_all_its_owners()
Last match wins.
Checks
assert codeowners_for(rules, "src/a.c") == (["@core", "@lead"], 2)assert codeowners_for(rules, "src/README.md") == (["@docs"], 3)assert codeowners_for(rules, "tools/x.py") == (["@all"], 1)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | catalog |
Source · 11 lines
def test_codeowners_last_match_wins_with_all_its_owners() -> None:
"""GitHub: "the last matching pattern takes the most precedence"; every owner on it applies.
@brief Last match wins.
"""
rules = parse_codeowners("* @all\n/src/ @core @lead\n*.md @docs\n")
assert codeowners_for(rules, "src/a.c") == (["@core", "@lead"], 2)
assert codeowners_for(rules, "src/README.md") == (["@docs"], 3)
assert codeowners_for(rules, "tools/x.py") == (["@all"], 1)
Activity · 4 steps
test_codeowners_patterns_follow_gitignore
None test_owners.test_codeowners_patterns_follow_gitignore()
gitignore semantics.
Checks
assert codeowners_for(rules, "docs/x/y.md") == (["@d"], 1)assert codeowners_for(rules, "build/a.c") == (["@b"], 2)assert codeowners_for(rules, "build/sub/a.c") is Noneassert codeowners_for(rules, "app/logs/out.txt") == (["@l"], 3)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | catalog |
Source · 12 lines
def test_codeowners_patterns_follow_gitignore() -> None:
"""An unanchored name matches at any depth; a leading `/` anchors; `*` stays in one segment.
@brief gitignore semantics.
"""
rules = parse_codeowners("docs/ @d\n/build/*.c @b\nlogs @l\n")
assert codeowners_for(rules, "docs/x/y.md") == (["@d"], 1)
assert codeowners_for(rules, "build/a.c") == (["@b"], 2)
assert codeowners_for(rules, "build/sub/a.c") is None
assert codeowners_for(rules, "app/logs/out.txt") == (["@l"], 3)
Activity · 5 steps
test_maintainers_every_matching_stanza_applies
None test_owners.test_maintainers_every_matching_stanza_applies()
MAINTAINERS stanzas.
Checks
assert [s.title for s in stanzas] == ["NET DRIVERS", "WIRELESS"]assert [s.title for s in stanzas if s.covers("drivers/net/eth.c")] == ["NET DRIVERS"]assert [s.title for s in stanzas if s.covers("drivers/net/wireless/a.c")] == ["WIRELESS"]assert [s.title for s in stanzas if s.covers("drivers/net/my_wifi.c")] == [
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | catalog |
Source · 16 lines
def test_maintainers_every_matching_stanza_applies() -> None:
"""Kernel rules: `F: dir/` covers below; `X:` excludes; `N:` is a regex over the path; every
stanza that matches applies.
@brief MAINTAINERS stanzas.
"""
stanzas = parse_maintainers(_MAINTAINERS)
assert [s.title for s in stanzas] == ["NET DRIVERS", "WIRELESS"]
assert [s.title for s in stanzas if s.covers("drivers/net/eth.c")] == ["NET DRIVERS"]
assert [s.title for s in stanzas if s.covers("drivers/net/wireless/a.c")] == ["WIRELESS"]
assert [s.title for s in stanzas if s.covers("drivers/net/my_wifi.c")] == [
"NET DRIVERS",
"WIRELESS",
]
Activity · 5 steps
test_the_layer_records_both_sources_and_is_created_empty
None test_owners.test_the_layer_records_both_sources_and_is_created_empty(Path tmp_path)
Rows per (file, owner, role, source); an owner-less repository still has the table.
Checks
assert record_owners(conn, repo) == 2assert rows == [assert record_owners(conn2, empty) == 0assert conn2.execute("SELECT count(*) FROM owners").fetchone() == (0,)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | measured | test_the_layer_records_both_sources_and_is_created_empty → record_owners |
Source · 27 lines
def test_the_layer_records_both_sources_and_is_created_empty(tmp_path: Path) -> None:
"""@brief Rows per (file, owner, role, source); an owner-less repository still has the table."""
repo = _index(
tmp_path,
{
".github/CODEOWNERS": "src/ @core\n",
"MAINTAINERS": "CORE\nM:\tAda <ada@example.org>\nF:\tsrc/\n",
"src/a.c": "int a;\n",
"tool.py": "x = 1\n",
},
)
conn = sqlite3.connect(tmp_path / "clew.db")
assert record_owners(conn, repo) == 2
rows = conn.execute(
"SELECT p.name, o.owner, o.role, o.source FROM owners o JOIN path p ON p.rowid = o.path_rowid"
" ORDER BY o.source"
).fetchall()
assert rows == [
("src/a.c", "@core", "owner", "codeowners"),
("src/a.c", "Ada <ada@example.org>", "maintainer", "maintainers"),
]
empty = _index(tmp_path / "e", {"src/a.c": "int a;\n"})
conn2 = sqlite3.connect(tmp_path / "e" / "clew.db")
assert record_owners(conn2, empty) == 0
assert conn2.execute("SELECT count(*) FROM owners").fetchone() == (0,)
Activity · 9 steps
test_the_owners_section_keys_match_the_reader
None test_owners.test_the_owners_section_keys_match_the_reader()
declaration.SECTION_KEYS['owners'] is the reader's own key set.
Checks
assert SECTION_KEYS["owners"] == OWNERS_KEYS
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-007 | catalog |
Source · 6 lines
def test_the_owners_section_keys_match_the_reader() -> None:
"""@brief declaration.SECTION_KEYS['owners'] is the reader's own key set."""
from clew.declaration import SECTION_KEYS
from clew.owners import OWNERS_KEYS
assert SECTION_KEYS["owners"] == OWNERS_KEYS1 more lines, not shown