Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions migrations/versions/eb7303e132c0_add_xmltv_regression_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
"""add_xmltv_regression_test

Revision ID: eb7303e132c0
Revises: c8f3a2b1d4e5
Create Date: 2026-01-06 21:43:46.009899

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = 'eb7303e132c0'
down_revision = 'c8f3a2b1d4e5'
branch_labels = None
depends_on = None


def upgrade():
conn = op.get_bind()

# 1. Check if the XMLTV regression test already exists
existing_test = conn.execute(
sa.text(
"SELECT id FROM regression_test "
"WHERE sample_id = 187 AND command = '--xmltv=1 --out=null'"
)
).fetchone()

if existing_test is not None:
# Already present, nothing to do
return

# 2. Insert regression test
conn.execute(
sa.text(
"""
INSERT INTO regression_test
(sample_id, command, input_type, output_type, expected_rc, active, description)
VALUES
(187, '--xmltv=1 --out=null', 'file', 'null', 10, 1,
'Validates ATSC XMLTV generation from broadcast EPG data (VCT/ETT/EIT)')
"""
)
)

# 3. Fetch newly created test id
test_id = conn.execute(
sa.text(
"SELECT id FROM regression_test "
"WHERE sample_id = 187 AND command = '--xmltv=1 --out=null'"
)
).fetchone()[0]

# 4. Get existing "General" category
cat_row = conn.execute(
sa.text("SELECT id FROM category WHERE name = 'General'")
).fetchone()

# Should exist on production
if cat_row is None:
raise RuntimeError("Required 'General' category not found")

category_id = cat_row[0]

# 5. Link regression test to category
conn.execute(
sa.text(
"INSERT INTO regression_test_category (regression_id, category_id) "
"VALUES (:test_id, :category_id)"
),
{"test_id": test_id, "category_id": category_id},
)

# 6. Insert expected XMLTV output (exit-code-only; ignore=1 skips file comparison).
# Keep `ignore` backticked: MySQL reserved word (unquoted -> 1064; SQLite hides it in CI).
conn.execute(
sa.text(
"""
INSERT INTO regression_test_output
(regression_id, correct, correct_extension, expected_filename, `ignore`)
VALUES
(:test_id, '', '.xml', '', 1)
"""
),
{"test_id": test_id},
)



def downgrade():
conn = op.get_bind()

test_row = conn.execute(

sa.text(
"SELECT id FROM regression_test "
"WHERE sample_id = 187 AND command = '--xmltv=1 --out=null'"
)
).fetchone()

if test_row is None:
return

test_id = test_row[0]

# Remove output first (FK dependency)
conn.execute(
sa.text(
"DELETE FROM regression_test_output WHERE regression_id = :test_id"
),
{"test_id": test_id},
)

# Remove category linkage
conn.execute(
sa.text(
"DELETE FROM regression_test_category WHERE regression_id = :test_id"
),
{"test_id": test_id},
)

# Remove regression test
conn.execute(
sa.text(
"DELETE FROM regression_test WHERE id = :test_id"
),
{"test_id": test_id},
)

1 change: 1 addition & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def setUp(self):

categories[0].regression_tests.append(regression_tests[0])
categories[2].regression_tests.append(regression_tests[1])

regression_test_outputs = [
RegressionTestOutput(1, "sample_out1", ".srt", ""),
RegressionTestOutput(2, "sample_out2", ".srt", "")
Expand Down
Loading