test_repair_attribute.py

tests/test_repair_attribute.py

Tests for repair_attribute_named_functions — fix doxygen's __attribute__ mislabel.

test_repair_merges_body_into_declaration

test_repair_attribute.test_repair_merges_body_into_declaration(tmp_path)

With a decl row present, the body transfers to it and the attribute row is deleted.

tests/test_repair_attribute.py:56

Checks

  • assert n == 1
  • assert attr == 0
  • assert rows == [(20, "real_fn", 2, 6)] # single row, decl now owns the body

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_repair_merges_body_into_declaration → repair_attribute_named_functions
REQ-DDB-PIPE-011measuredtest_repair_merges_body_into_declaration → repair_attribute_named_functions → _real_function_name_at → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_repair_merges_body_into_declaration → repair_attribute_named_functions → _real_function_name_at → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language
Source · 16 lines
def test_repair_merges_body_into_declaration(tmp_path):
    (tmp_path / "mod.c").write_text(_SRC)
    db = tmp_path / "d.db"
    _make_db(db, with_decl=True)
    n = repair_attribute_named_functions(db, tmp_path)
    assert n == 1
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT rowid, name, bodystart, bodyend FROM memberdef WHERE name='real_fn'"
    ).fetchall()
    attr = conn.execute("SELECT COUNT(*) FROM memberdef WHERE name='__attribute__'").fetchone()[0]
    conn.close()
    assert attr == 0
    assert rows == [(20, "real_fn", 2, 6)]  # single row, decl now owns the body

Activity · 11 steps
lines 57–57(tmp_path / "mod.c").write_text(_SRC)lines 58–58db = tmp_path / "d.db"lines 59–59_make_db(db, with_decl=True)lines 60–60n = repair_attribute_named_functions(db, tmp_path)lines 61–61assert n == 1lines 62–62conn = sqlite3.connect(str(db))lines 63–65rows = conn.execute( "SELECT rowid, name, bodystart, bodyend FROM memberdef WHERE name='real_fn'" ).fetchall()lines 66–66attr = conn.execute("SELECT COUNT(*) FROM memberdef WHERE name='__attribute__'").fetchone()[0]lines 67–67conn.close()lines 68–68assert attr == 0lines 69–69assert rows == [(20, "real_fn", 2, 6)]

test_repair_noop_without_attribute_rows

test_repair_attribute.test_repair_noop_without_attribute_rows(tmp_path)

No attribute rows -> no-op.

tests/test_repair_attribute.py:90

Checks

  • assert repair_attribute_named_functions(db, tmp_path) == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_repair_noop_without_attribute_rows → repair_attribute_named_functions
REQ-DDB-PIPE-011inferredtest_repair_noop_without_attribute_rows → repair_attribute_named_functions → _real_function_name_at → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_repair_noop_without_attribute_rows → repair_attribute_named_functions → _real_function_name_at → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language
Source · 14 lines
def test_repair_noop_without_attribute_rows(tmp_path):
    db = tmp_path / "d.db"
    conn = sqlite3.connect(str(db))
    conn.executescript(
        "CREATE TABLE path(rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER);"
        "CREATE TABLE memberdef(rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT,"
        " file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER);"
        "INSERT INTO path(rowid,name,type) VALUES(1,'mod.c',1);"
        "INSERT INTO memberdef(rowid,name,kind,file_id,bodyfile_id,bodystart,bodyend)"
        " VALUES(1,'ok_fn','function',1,1,2,4);"
    )
    conn.commit()
    conn.close()
    assert repair_attribute_named_functions(db, tmp_path) == 0

1 more lines, not shown

Activity · 6 steps
lines 91–91db = tmp_path / "d.db"lines 92–92conn = sqlite3.connect(str(db))lines 93–100conn.executescript( "CREATE TABLE path(rowid INTEGER PRIMARY KEY, name TEXT, type INTEGER);" "CREATE TABLE memberdef(rowid INTEGER PRIMARY KEY, name TEXT, kind TEXT," " file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER);" "INSERT INTO path(rowid,name,type) VALUES(1,'mod.c',1);" "INSERT INTO memberdef(rowid,name,kind,file_id,bodyfile_id,bodystart,bodyend)" " VALUES(1,'ok_fn','function',1,1,2,4);" )lines 101–101conn.commit()lines 102–102conn.close()lines 103–103assert repair_attribute_named_functions(db, tmp_path) == 0

test_repair_renames_when_no_declaration

test_repair_attribute.test_repair_renames_when_no_declaration(tmp_path)

With no decl row, the attribute row is renamed in place.

tests/test_repair_attribute.py:74

Checks

  • assert n == 1
  • assert row == (10, "real_fn", 2) # same row, renamed

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_repair_renames_when_no_declaration → repair_attribute_named_functions
REQ-DDB-PIPE-011measuredtest_repair_renames_when_no_declaration → repair_attribute_named_functions → _real_function_name_at → _ast_parse_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_repair_renames_when_no_declaration → repair_attribute_named_functions → _real_function_name_at → _ast_parse_one_file → _ts_language_for → _grammar_available → has_language
Source · 14 lines
def test_repair_renames_when_no_declaration(tmp_path):
    (tmp_path / "mod.c").write_text(_SRC)
    db = tmp_path / "d.db"
    _make_db(db, with_decl=False)
    n = repair_attribute_named_functions(db, tmp_path)
    assert n == 1
    conn = sqlite3.connect(str(db))
    row = conn.execute(
        "SELECT rowid, name, bodystart FROM memberdef WHERE name='real_fn'"
    ).fetchone()
    conn.close()
    assert row == (10, "real_fn", 2)  # same row, renamed

Activity · 9 steps
lines 75–75(tmp_path / "mod.c").write_text(_SRC)lines 76–76db = tmp_path / "d.db"lines 77–77_make_db(db, with_decl=False)lines 78–78n = repair_attribute_named_functions(db, tmp_path)lines 79–79assert n == 1lines 80–80conn = sqlite3.connect(str(db))lines 81–83row = conn.execute( "SELECT rowid, name, bodystart FROM memberdef WHERE name='real_fn'" ).fetchone()lines 84–84conn.close()lines 85–85assert row == (10, "real_fn", 2)