MCPcopy Create free account
hub / github.com/idank/explainshell / TestCheck

Class TestCheck

tests/test_db_check.py:44–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42
43
44class TestCheck:
45 def test_clean_db(self, store, db_path):
46 store.add_manpage(_make_manpage("tar", "1"), _make_raw())
47 assert db_check(db_path) == []
48
49 def test_malformed_source(self, store, db_path):
50 """Directly insert a row with a bare source to test the checker."""
51 store._conn.execute("PRAGMA foreign_keys = OFF")
52 store._conn.execute(
53 "INSERT INTO parsed_manpages(source, name, options, aliases) VALUES (?, ?, '[]', '[]')",
54 ("tar.1.gz", "tar"),
55 )
56 store._conn.commit()
57 store._conn.execute("PRAGMA foreign_keys = ON")
58 issues = db_check(db_path)
59 errors_list = [msg for sev, msg in issues if sev == "error"]
60 assert any("malformed source path" in msg for msg in errors_list)
61
62 def test_orphaned_mapping(self, store, db_path):
63 """Insert a mapping pointing to a non-existent manpage."""
64 store._conn.execute("PRAGMA foreign_keys = OFF")
65 store._conn.execute(
66 "INSERT INTO mappings(src, dst, score) VALUES (?, ?, ?)",
67 ("ghost", "ubuntu/26.04/1/ghost.1.gz", 10),
68 )
69 store._conn.commit()
70 store._conn.execute("PRAGMA foreign_keys = ON")
71 issues = db_check(db_path)
72 errors_list = [msg for sev, msg in issues if sev == "error"]
73 assert any("orphaned mapping" in msg for msg in errors_list)
74
75 def test_unreachable_manpage(self, store, db_path):
76 """A manpage with no mappings should be flagged as a warning."""
77 store._conn.execute("PRAGMA foreign_keys = OFF")
78 store._conn.execute(
79 "INSERT INTO parsed_manpages(source, name, options, aliases) "
80 "VALUES (?, ?, '[]', '[]')",
81 ("ubuntu/26.04/1/lonely.1.gz", "lonely"),
82 )
83 store._conn.commit()
84 store._conn.execute("PRAGMA foreign_keys = ON")
85 issues = db_check(db_path)
86 warnings = [msg for sev, msg in issues if sev == "warning"]
87 assert any("unreachable manpage" in msg for msg in warnings)
88
89 def test_shadowed_duplicate(self, store, db_path):
90 """Two manpages with same name+section+distro should be flagged."""
91 store.add_manpage(_make_manpage("ps", "1"), _make_raw())
92 # Directly insert a second one with same name/section/distro but different source
93 store._conn.execute("PRAGMA foreign_keys = OFF")
94 store._conn.execute(
95 "INSERT INTO parsed_manpages(source, name, options, aliases) "
96 "VALUES (?, ?, '[]', '[]')",
97 ("ubuntu/26.04/1/procps-ps.1.gz", "ps"),
98 )
99 store._conn.commit()
100 store._conn.execute("PRAGMA foreign_keys = ON")
101 issues = db_check(db_path)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected