-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_metadata.py
More file actions
50 lines (42 loc) · 1.58 KB
/
test_metadata.py
File metadata and controls
50 lines (42 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from minidb import MiniDB
import os
import shutil
def test_metadata():
test_dir = "test_metadata_data"
if os.path.exists(test_dir):
shutil.rmtree(test_dir)
db = MiniDB(data_dir=test_dir)
db.execute_query("CREATE TABLE users (id, username)")
db.execute_query("CREATE TABLE posts (id, title, author_id)")
# 1. Test SHOW TABLES
print("Executing SHOW TABLES...")
res = db.execute_query("SHOW TABLES")
print(f"Result: {res}")
# New format is list of dicts: [{'table_name': 'name'}, ...]
table_names = {row['table_name'] for row in res}
if table_names == {"users", "posts"}:
print("[v] SHOW TABLES works correctly.")
else:
print(f"[x] SHOW TABLES failed: {res}")
# 2. Test get_tables() method (still returns list of strings)
print("\nCalling db.get_tables()...")
res_method = db.get_tables()
print(f"Result: {res_method}")
if set(res_method) == {"users", "posts"}:
print("[v] get_tables() method works correctly.")
else:
print(f"[x] get_tables() method failed: {res_method}")
# 3. Test DESCRIBE (regression)
print("\nExecuting DESCRIBE users...")
res_desc = db.execute_query("DESCRIBE users")
print(f"Result: {res_desc}")
if res_desc['columns'] == ['id', 'username']:
print("[v] DESCRIBE users still works.")
else:
print(f"[x] DESCRIBE users failed: {res_desc}")
# Cleanup
if os.path.exists(test_dir):
shutil.rmtree(test_dir)
print("\n--- Metadata Verification Complete ---")
if __name__ == "__main__":
test_metadata()