Skip to content

Commit 7babf11

Browse files
committed
Add Alembic migration for WebVTT regression test
1 parent 456eaf9 commit 7babf11

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
"""Add WebVTT regression test
2+
3+
Revision ID: c1a2b3d4e5f6
4+
Revises: b3ed927671bd
5+
Create Date: 2026-01-04 21:05:00.000000
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
from sqlalchemy import text
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'c1a2b3d4e5f6'
14+
down_revision = 'b3ed927671bd'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
conn = op.get_bind()
21+
22+
# 1. Insert "Output Formats" category if not exists
23+
existing_cat = conn.execute(
24+
text("SELECT id FROM category WHERE name = 'Output Formats'")
25+
).fetchone()
26+
27+
if existing_cat is None:
28+
conn.execute(
29+
text("INSERT INTO category (name, description) VALUES ('Output Formats', 'Tests for specific output format generation')")
30+
)
31+
category_id = conn.execute(text("SELECT id FROM category WHERE name = 'Output Formats'")).fetchone()[0]
32+
else:
33+
category_id = existing_cat[0]
34+
35+
# 2. Check if WebVTT regression test already exists
36+
existing_test = conn.execute(
37+
text("SELECT id FROM regression_test WHERE command = '-out=webvtt' AND sample_id = 1")
38+
).fetchone()
39+
40+
if existing_test is None:
41+
# 3. Insert the WebVTT regression test (sample_id=1 is sample1.ts)
42+
conn.execute(
43+
text("""
44+
INSERT INTO regression_test (sample_id, command, input_type, output_type, expected_rc, active, description)
45+
VALUES (1, '-out=webvtt', 'file', 'file', 0, 1, 'Validates WebVTT header generation on empty-caption input')
46+
""")
47+
)
48+
test_id = conn.execute(
49+
text("SELECT id FROM regression_test WHERE command = '-out=webvtt' AND sample_id = 1")
50+
).fetchone()[0]
51+
52+
# 4. Insert RegressionTestOutput with the golden content
53+
conn.execute(
54+
text("""
55+
INSERT INTO regression_test_output (regression_id, correct, correct_extension, expected_filename)
56+
VALUES (:test_id, 'WEBVTT\r\n\r\n', '.webvtt', 'sample1.webvtt')
57+
"""),
58+
{"test_id": test_id}
59+
)
60+
61+
# 5. Link test to category
62+
conn.execute(
63+
text("""
64+
INSERT INTO regression_test_category (regression_id, category_id)
65+
VALUES (:test_id, :cat_id)
66+
"""),
67+
{"test_id": test_id, "cat_id": category_id}
68+
)
69+
70+
71+
def downgrade():
72+
conn = op.get_bind()
73+
74+
# Get the WebVTT test ID
75+
test_row = conn.execute(
76+
text("SELECT id FROM regression_test WHERE command = '-out=webvtt' AND sample_id = 1")
77+
).fetchone()
78+
79+
if test_row is not None:
80+
test_id = test_row[0]
81+
82+
# Delete in reverse order of dependencies
83+
conn.execute(
84+
text("DELETE FROM regression_test_category WHERE regression_id = :test_id"),
85+
{"test_id": test_id}
86+
)
87+
conn.execute(
88+
text("DELETE FROM regression_test_output WHERE regression_id = :test_id"),
89+
{"test_id": test_id}
90+
)
91+
conn.execute(
92+
text("DELETE FROM regression_test WHERE id = :test_id"),
93+
{"test_id": test_id}
94+
)
95+
96+
# Check if "Output Formats" category has any remaining tests
97+
cat_row = conn.execute(
98+
text("SELECT id FROM category WHERE name = 'Output Formats'")
99+
).fetchone()
100+
101+
if cat_row is not None:
102+
category_id = cat_row[0]
103+
remaining = conn.execute(
104+
text("SELECT COUNT(*) FROM regression_test_category WHERE category_id = :cat_id"),
105+
{"cat_id": category_id}
106+
).fetchone()[0]
107+
108+
if remaining == 0:
109+
conn.execute(
110+
text("DELETE FROM category WHERE id = :cat_id"),
111+
{"cat_id": category_id}
112+
)

0 commit comments

Comments
 (0)