Skip to content

Commit

Permalink
Update db test
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwal committed Jul 26, 2024
1 parent a53c1f6 commit a604e9a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ dependencies = [
]

[tool.hatch.envs.test.scripts]
all = "python -m pytest src/hydrusvideodeduplicator/pdqhashing/tests tests/test_dedupe.py tests/test_vpdqpy.py --verbose {args}"
all = "python -m pytest tests/test_db.py src/hydrusvideodeduplicator/pdqhashing/tests tests/test_dedupe.py tests/test_vpdqpy.py --verbose {args}"
pdq = "python -m pytest src/hydrusvideodeduplicator/pdqhashing/tests --verbose {args}"
db = "python -m pytest tests/test_db.py --verbose {args}"

Expand Down
51 changes: 39 additions & 12 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,49 @@ def test_create_db(self):
# Check tables
res = cur.execute("SELECT name FROM sqlite_master WHERE type='table'")
self.assertEqual(
res.fetchall(),
[
("videos",),
("version",),
],
set(res.fetchall()),
set(
[
("version",),
("files",),
("phashed_file_queue",),
("shape_maintenance_branch_regen",),
("shape_perceptual_hash_map",),
("shape_perceptual_hashes",),
("shape_search_cache",),
("shape_vptree",),
]
),
)

# Check the database is queryable (this may be overkill)
with self.assertRaises(sqlite3.OperationalError):
_ = cur.execute("SELECT key1 FROM videos")

# Check videos table
res = cur.execute("SELECT key FROM videos")
self.assertEqual(len(res.fetchall()), 0)
res = cur.execute("SELECT value FROM videos")
self.assertEqual(len(res.fetchall()), 0)
_ = cur.execute("SELECT foo FROM files")

def check_table_columns(table: str, expected_columns: list[str]):
for column in expected_columns:
res = cur.execute(f"SELECT {column} FROM {table}")
self.assertEqual(len(res.fetchall()), 0)

expected_tables = {
"files": ["hash_id", "file_hash"],
"phashed_file_queue": ["file_hash", "phash"],
"shape_maintenance_branch_regen": ["phash_id"],
"shape_perceptual_hash_map": ["phash_id", "hash_id"],
"shape_perceptual_hashes": ["phash_id", "phash"],
"shape_search_cache": ["hash_id", "searched_distance"],
"shape_vptree": [
"phash_id",
"parent_id",
"radius",
"inner_id",
"inner_population",
"outer_id",
"outer_population",
],
}
for table, cols in expected_tables.items():
check_table_columns(table, cols)

# Check version table
res = cur.execute("SELECT version FROM version")
Expand Down

0 comments on commit a604e9a

Please sign in to comment.