test_kerneldoc.py¶
tests/test_kerneldoc.py
kernel-doc blocks are read into their own layer; doxygen blocks are not (S6; 2.0.0, index only).
test_a_function_block_is_read_with_its_parameters_and_sections
None test_kerneldoc.test_a_function_block_is_read_with_its_parameters_and_sections()
Name, brief,
Checks
assert (fn["kind"], fn["name"], fn["brief"]) == ("function", "dev_open", "Open the device.")assert json.loads(fn["params"]) == {assert fn["context"] == "Process context. Sleeps."assert fn["returns"] == "0 on success, a negative errno otherwise."assert "Takes the device lock" in fn["description"]assert fn["line"] == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-009 | measured | test_a_function_block_is_read_with_its_parameters_and_sections → parse_kerneldoc |
Source · 14 lines
def test_a_function_block_is_read_with_its_parameters_and_sections() -> None:
"""@brief Name, brief, @args (with a continuation line), Context and Return."""
(fn, *_rest) = parse_kerneldoc(_SOURCE)
assert (fn["kind"], fn["name"], fn["brief"]) == ("function", "dev_open", "Open the device.")
assert json.loads(fn["params"]) == {
"dev": "The device, already probed.",
"flags": "O_* flags; O_NONBLOCK returns at once.",
}
assert fn["context"] == "Process context. Sleeps."
assert fn["returns"] == "0 on success, a negative errno otherwise."
assert "Takes the device lock" in fn["description"]
assert fn["line"] == 1
Activity · 7 steps
test_struct_and_doc_blocks_are_read_and_a_doxygen_block_is_not
None test_kerneldoc.test_struct_and_doc_blocks_are_read_and_a_doxygen_block_is_not()
`struct foo -` and `DOC:` are kernel-doc; an `@brief` block is doxygen's.
Checks
assert [(b["kind"], b["name"]) for b in blocks] == [assert blocks[2]["brief"] == "Locking"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-009 | measured | test_struct_and_doc_blocks_are_read_and_a_doxygen_block_is_not → parse_kerneldoc |
Source · 11 lines
def test_struct_and_doc_blocks_are_read_and_a_doxygen_block_is_not() -> None:
"""@brief `struct foo -` and `DOC:` are kernel-doc; an `@brief` block is doxygen's."""
blocks = parse_kerneldoc(_SOURCE)
assert [(b["kind"], b["name"]) for b in blocks] == [
("function", "dev_open"),
("struct", "dev_ops"),
("doc", ""),
]
assert blocks[2]["brief"] == "Locking"
Activity · 3 steps
test_the_layer_records_c_files_only_and_exists_when_empty
None test_kerneldoc.test_the_layer_records_c_files_only_and_exists_when_empty(Path tmp_path)
Rows for a C file; a Python file is not read; the table exists with no rows.
Checks
assert ingest_kerneldoc(db, repo) == 3assert files == {"dev.c"}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_the_layer_records_c_files_only_and_exists_when_empty → ingest_kerneldoc → kerneldoc_of → memoized |
| REQ-DDB-INDEX-009 | measured | test_the_layer_records_c_files_only_and_exists_when_empty → ingest_kerneldoc |
| REQ-DDB-PIPE-014 | measured | test_the_layer_records_c_files_only_and_exists_when_empty → ingest_kerneldoc → within_repo |
Source · 15 lines
def test_the_layer_records_c_files_only_and_exists_when_empty(tmp_path: Path) -> None:
"""@brief Rows for a C file; a Python file is not read; the table exists with no rows."""
repo = tmp_path / "repo"
repo.mkdir()
(repo / "dev.c").write_text(_SOURCE)
(repo / "tool.py").write_text('"""foo() - not kernel-doc."""\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)", [("dev.c",), ("tool.py",)])
conn.commit()
conn.close()
assert ingest_kerneldoc(db, repo) == 3
files = {r[0] for r in sqlite3.connect(db).execute("SELECT file_path FROM kerneldoc")}
assert files == {"dev.c"}1 more lines, not shown