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.

tests/test_owners.py:125

Show on the map →

Called by none

Calls _index, record_owners

Checks

  • assert conn.execute("SELECT owner FROM owners").fetchall() == [("@meta",)]
  • assert conn.execute("SELECT count(*) FROM owners").fetchone() == (0,)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007measuredtest_a_declared_owners_file_is_read_and_a_missing_one_is_not_replaced → record_owners
REQ-DDB-PIPE-014measured
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
lines 127–130repo = _index( tmp_path, {"CODEOWNERS": "* @root\n", "meta/OWNERS": "* @meta\n", "src/a.c": "int a;\n"}, )lines 131–131conn = sqlite3.connect(tmp_path / "clew.db")lines 132–132record_owners(conn, repo, {"codeowners": "meta/OWNERS"})lines 133–133assert conn.execute("SELECT owner FROM owners").fetchall() == [("@meta",)]lines 134–134record_owners(conn, repo, {"codeowners": "missing/OWNERS"})lines 135–135assert conn.execute("SELECT count(*) FROM owners").fetchone() == (0,)

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).

tests/test_owners.py:41

Show on the map →

Called by none

Calls codeowners_for, parse_codeowners

Checks

  • assert codeowners_for(rules, "vendor/lib.c") == ([], 2)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007catalog
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
lines 43–43rules = parse_codeowners("* @all\n/vendor/\n")lines 44–44assert codeowners_for(rules, "vendor/lib.c") == ([], 2)

test_codeowners_last_match_wins_with_all_its_owners

None test_owners.test_codeowners_last_match_wins_with_all_its_owners()

Last match wins.

tests/test_owners.py:18

Show on the map →

Called by none

Calls codeowners_for, parse_codeowners

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007catalog
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
lines 23–23rules = parse_codeowners("* @all\n/src/ @core @lead\n*.md @docs\n")lines 24–24assert codeowners_for(rules, "src/a.c") == (["@core", "@lead"], 2)lines 25–25assert codeowners_for(rules, "src/README.md") == (["@docs"], 3)lines 26–26assert codeowners_for(rules, "tools/x.py") == (["@all"], 1)

test_codeowners_patterns_follow_gitignore

None test_owners.test_codeowners_patterns_follow_gitignore()

gitignore semantics.

tests/test_owners.py:29

Show on the map →

Called by none

Calls codeowners_for, parse_codeowners

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 None
  • assert codeowners_for(rules, "app/logs/out.txt") == (["@l"], 3)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007catalog
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
lines 34–34rules = parse_codeowners("docs/ @d\n/build/*.c @b\nlogs @l\n")lines 35–35assert codeowners_for(rules, "docs/x/y.md") == (["@d"], 1)lines 36–36assert codeowners_for(rules, "build/a.c") == (["@b"], 2)lines 37–37assert codeowners_for(rules, "build/sub/a.c") is Nonelines 38–38assert codeowners_for(rules, "app/logs/out.txt") == (["@l"], 3)

test_maintainers_every_matching_stanza_applies

None test_owners.test_maintainers_every_matching_stanza_applies()

MAINTAINERS stanzas.

tests/test_owners.py:64

Show on the map →

Called by none

Calls parse_maintainers

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007catalog
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
lines 70–70stanzas = parse_maintainers(_MAINTAINERS)lines 71–71assert [s.title for s in stanzas] == ["NET DRIVERS", "WIRELESS"]lines 72–72assert [s.title for s in stanzas if s.covers("drivers/net/eth.c")] == ["NET DRIVERS"]lines 73–73assert [s.title for s in stanzas if s.covers("drivers/net/wireless/a.c")] == ["WIRELESS"]lines 74–77assert [s.title for s in stanzas if s.covers("drivers/net/my_wifi.c")] == [ "NET DRIVERS", "WIRELESS", ]

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.

tests/test_owners.py:98

Show on the map →

Called by none

Calls _index, record_owners

Checks

  • assert record_owners(conn, repo) == 2
  • assert rows == [
  • assert record_owners(conn2, empty) == 0
  • assert conn2.execute("SELECT count(*) FROM owners").fetchone() == (0,)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007measuredtest_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
lines 100–108repo = _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", }, )lines 109–109conn = sqlite3.connect(tmp_path / "clew.db")lines 110–110assert record_owners(conn, repo) == 2lines 111–114rows = 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()lines 115–118assert rows == [ ("src/a.c", "@core", "owner", "codeowners"), ("src/a.c", "Ada <ada@example.org>", "maintainer", "maintainers"), ]lines 119–119empty = _index(tmp_path / "e", {"src/a.c": "int a;\n"})lines 120–120conn2 = sqlite3.connect(tmp_path / "e" / "clew.db")lines 121–121assert record_owners(conn2, empty) == 0lines 122–122assert conn2.execute("SELECT count(*) FROM owners").fetchone() == (0,)

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.

tests/test_owners.py:138

Show on the map →

Called by none

Calls none

Checks

  • assert SECTION_KEYS["owners"] == OWNERS_KEYS

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-007catalog
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_KEYS

1 more lines, not shown

Activity · 3 steps
lines 140–140from clew.declaration import SECTION_KEYSlines 141–141from clew.owners import OWNERS_KEYSlines 143–143assert SECTION_KEYS["owners"] == OWNERS_KEYS