From 8a46ef49b99db18a0e4353c191b6427d4edec04f Mon Sep 17 00:00:00 2001 From: CI Bot Date: Mon, 31 Aug 2026 11:10:45 +0000 Subject: [PATCH] style: auto-format with black + isort + prettier [skip ci-format-check] --- ...grate_template_segments_to_clip_configs.py | 8 ++----- .../sqlalchemy_impl/template_repository.py | 24 +++++++++---------- tests/unit/test_unify_template_segments.py | 20 ++++------------ 3 files changed, 18 insertions(+), 34 deletions(-) diff --git a/alembic/versions/060_migrate_template_segments_to_clip_configs.py b/alembic/versions/060_migrate_template_segments_to_clip_configs.py index 65641ca23..001d3ab14 100644 --- a/alembic/versions/060_migrate_template_segments_to_clip_configs.py +++ b/alembic/versions/060_migrate_template_segments_to_clip_configs.py @@ -27,9 +27,7 @@ def upgrade() -> None: # material_type -> config JSON {"material_type": ...} # clip_type -> "main" (默认值) # 只迁移 template_clip_configs 中没有对应 template_id 的记录 - op.execute( - sa.text( - """ + op.execute(sa.text(""" INSERT INTO template_clip_configs (id, template_id, clip_type, "order", min_duration, max_duration, text_template, material_requirements, transition_effect, config, @@ -56,9 +54,7 @@ def upgrade() -> None: SELECT 1 FROM template_clip_configs c WHERE c.template_id = s.template_id ) - """ - ) - ) + """)) def downgrade() -> None: diff --git a/packages/adapters/sqlalchemy_impl/template_repository.py b/packages/adapters/sqlalchemy_impl/template_repository.py index eb830f977..766bce6ac 100755 --- a/packages/adapters/sqlalchemy_impl/template_repository.py +++ b/packages/adapters/sqlalchemy_impl/template_repository.py @@ -218,14 +218,16 @@ class SQLAlchemyTemplateRepository: # 复用 create_segments 写入 template_clip_configs new_segments: List[TemplateSegment] = [] for seg in source.segments: - new_segments.append(TemplateSegment( - id=str(uuid.uuid4()), - template_id=created.id, - segment_order=seg.segment_order, - duration_min=seg.duration_min, - duration_max=seg.duration_max, - material_type=seg.material_type, - )) + new_segments.append( + TemplateSegment( + id=str(uuid.uuid4()), + template_id=created.id, + segment_order=seg.segment_order, + duration_min=seg.duration_min, + duration_max=seg.duration_max, + material_type=seg.material_type, + ) + ) if new_segments: self.create_segments(new_segments) else: @@ -282,11 +284,7 @@ class SQLAlchemyTemplateRepository: .filter(TemplateClipConfigModel.template_id == template_id) .delete() ) - c2 = ( - self.session.query(TemplateSegmentModel) - .filter(TemplateSegmentModel.template_id == template_id) - .delete() - ) + c2 = self.session.query(TemplateSegmentModel).filter(TemplateSegmentModel.template_id == template_id).delete() self.session.commit() return c1 + c2 diff --git a/tests/unit/test_unify_template_segments.py b/tests/unit/test_unify_template_segments.py index 495f802e6..d1518570b 100644 --- a/tests/unit/test_unify_template_segments.py +++ b/tests/unit/test_unify_template_segments.py @@ -88,9 +88,7 @@ class TestCreateSegments: seg = _make_segment(tpl.id, order=1) repo.create_segments([seg]) - clips = session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == tpl.id - ).all() + clips = session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == tpl.id).all() assert len(clips) == 1 assert clips[0].clip_type == "main" assert clips[0].order == 1 @@ -105,9 +103,7 @@ class TestCreateSegments: seg = _make_segment(tpl.id, order=1, material_type="voiceover") repo.create_segments([seg]) - clip = session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == tpl.id - ).first() + clip = session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == tpl.id).first() assert clip.config["material_type"] == "voiceover" @@ -232,9 +228,7 @@ class TestCopyTemplate: assert len(copied.segments) == 1 # 验证写入的是 clip_configs 表 - clips = session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == copied.id - ).all() + clips = session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == copied.id).all() assert len(clips) == 1 assert clips[0].config["material_type"] == "voiceover" @@ -272,12 +266,8 @@ class TestDelete: repo.delete(tpl.id, "u1") # 两张表都应该被清理 - c1 = session.query(TemplateClipConfigModel).filter( - TemplateClipConfigModel.template_id == tpl.id - ).count() - c2 = session.query(TemplateSegmentModel).filter( - TemplateSegmentModel.template_id == tpl.id - ).count() + c1 = session.query(TemplateClipConfigModel).filter(TemplateClipConfigModel.template_id == tpl.id).count() + c2 = session.query(TemplateSegmentModel).filter(TemplateSegmentModel.template_id == tpl.id).count() assert c1 == 0 assert c2 == 0