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,

tests/test_kerneldoc.py:50

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

requirementlinkedpath to the implementer
REQ-DDB-INDEX-009measuredtest_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
lines 52–52(fn, *_rest) = parse_kerneldoc(_SOURCE)lines 53–53assert (fn["kind"], fn["name"], fn["brief"]) == ("function", "dev_open", "Open the device.")lines 54–57assert json.loads(fn["params"]) == { "dev": "The device, already probed.", "flags": "O_* flags; O_NONBLOCK returns at once.", }lines 58–58assert fn["context"] == "Process context. Sleeps."lines 59–59assert fn["returns"] == "0 on success, a negative errno otherwise."lines 60–60assert "Takes the device lock" in fn["description"]lines 61–61assert fn["line"] == 1

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.

tests/test_kerneldoc.py:64

Checks

  • assert [(b["kind"], b["name"]) for b in blocks] == [
  • assert blocks[2]["brief"] == "Locking"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-009measuredtest_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
lines 66–66blocks = parse_kerneldoc(_SOURCE)lines 67–71assert [(b["kind"], b["name"]) for b in blocks] == [ ("function", "dev_open"), ("struct", "dev_ops"), ("doc", ""), ]lines 72–72assert blocks[2]["brief"] == "Locking"

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.

tests/test_kerneldoc.py:75

Checks

  • assert ingest_kerneldoc(db, repo) == 3
  • assert files == {"dev.c"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_the_layer_records_c_files_only_and_exists_when_empty → ingest_kerneldoc → kerneldoc_of → memoized
REQ-DDB-INDEX-009measuredtest_the_layer_records_c_files_only_and_exists_when_empty → ingest_kerneldoc
REQ-DDB-PIPE-014measuredtest_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

Activity · 13 steps
lines 77–77repo = tmp_path / "repo"lines 78–78repo.mkdir()lines 79–79(repo / "dev.c").write_text(_SOURCE)lines 80–80(repo / "tool.py").write_text('"""foo() - not kernel-doc."""\n')lines 81–81db = tmp_path / "clew.db"lines 82–82conn = sqlite3.connect(db)lines 83–83conn.execute("CREATE TABLE path (rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER)")lines 84–84conn.executemany("INSERT INTO path(name, type) VALUES (?, 1)", [("dev.c",), ("tool.py",)])lines 85–85conn.commit()lines 86–86conn.close()lines 87–87assert ingest_kerneldoc(db, repo) == 3lines 88–88files = {r[0] for r in sqlite3.connect(db).execute("SELECT file_path FROM kerneldoc")}lines 89–89assert files == {"dev.c"}