diff --git a/tests/unit/test_dedup_pure.py b/tests/unit/test_dedup_pure.py index 9c82021b8..cc58e6d9a 100755 --- a/tests/unit/test_dedup_pure.py +++ b/tests/unit/test_dedup_pure.py @@ -10,6 +10,9 @@ import pytest # 模块级mock cv2(dedup模块import时需要) sys.modules["cv2"] = MagicMock() +# 模块级mock worker_app.db(dedup模块import时会触发数据库初始化,纯算法测试不需要) +sys.modules["worker_app.db"] = MagicMock() +sys.modules["worker_app.db"].SessionLocal = MagicMock() from video_processing.dedup import ( # noqa: E402 VideoDeduplicator, diff --git a/tests/unit/test_domain_remaining_small_modules.py b/tests/unit/test_domain_remaining_small_modules.py index e77f586cb..54faec9e3 100755 --- a/tests/unit/test_domain_remaining_small_modules.py +++ b/tests/unit/test_domain_remaining_small_modules.py @@ -1,3 +1,5 @@ +from dataclasses import FrozenInstanceError + """domain 层剩余小模块单测 - bgm_utils/exceptions/editing_mode/recipe/template/template_version/template_clip_config/preset_bgm/preset_voices/title_library/voice_library""" import pytest @@ -397,7 +399,7 @@ class TestPresetBGM: def test_preset_bgm_frozen(self): bgm = PresetBGM(id="t1", name="t", style="x", duration=10.0) - with pytest.raises(Exception): + with pytest.raises(FrozenInstanceError): bgm.name = "改名" def test_library_not_empty(self): @@ -487,7 +489,7 @@ class TestPresetVoices: def test_preset_voice_frozen(self): v = PresetVoice(voice_id="v1", name="t", description="d", gender="female") - with pytest.raises(Exception): + with pytest.raises(FrozenInstanceError): v.name = "改名" def test_preset_voices_list_not_empty(self): diff --git a/tests/unit/test_email_service_smtp.py b/tests/unit/test_email_service_smtp.py index 8f32d1dde..36c340d81 100755 --- a/tests/unit/test_email_service_smtp.py +++ b/tests/unit/test_email_service_smtp.py @@ -267,4 +267,4 @@ class TestGetEmailService: svc1 = get_email_service() svc2 = get_email_service() # 两个都可能是 Noop 或 EmailService,取决于环境 - assert type(svc1) == type(svc2) + assert type(svc1) is type(svc2) diff --git a/tests/unit/test_filter_presets.py b/tests/unit/test_filter_presets.py index 903bc0ac2..98efba87e 100755 --- a/tests/unit/test_filter_presets.py +++ b/tests/unit/test_filter_presets.py @@ -1,3 +1,5 @@ +from dataclasses import FrozenInstanceError + """filter_presets 领域层单元测试 - 滤镜预设库""" import pytest @@ -58,7 +60,7 @@ class TestFilterPreset: def test_frozen_immutable(self): """frozen dataclass 不可修改""" preset = FilterPreset(id="test", name="测试", category="basic") - with pytest.raises(Exception): # FrozenInstanceError + with pytest.raises(FrozenInstanceError): preset.name = "改名" def test_tags_default_empty_list(self): diff --git a/tests/unit/test_jwt_handler.py b/tests/unit/test_jwt_handler.py index 1c8859539..116062c32 100755 --- a/tests/unit/test_jwt_handler.py +++ b/tests/unit/test_jwt_handler.py @@ -5,6 +5,7 @@ from __future__ import annotations import time import pytest +from jwt.exceptions import ExpiredSignatureError, InvalidTokenError from packages.application.auth.jwt_handler import ( JWTHandler, @@ -86,17 +87,17 @@ class TestJWTHandler: # 等待一小段时间确保过期 time.sleep(0.1) - with pytest.raises(Exception): + with pytest.raises(ExpiredSignatureError): handler.verify_access_token(token) def test_invalid_token_raises_error(self, jwt_handler): """无效 token 验证失败""" - with pytest.raises(Exception): + with pytest.raises(InvalidTokenError): jwt_handler.verify_access_token("invalid.token.here") def test_empty_token_raises_error(self, jwt_handler): """空字符串 token 验证失败""" - with pytest.raises(Exception): + with pytest.raises(InvalidTokenError): jwt_handler.verify_access_token("") def test_different_secret_fails_verification(self): @@ -106,7 +107,7 @@ class TestJWTHandler: token = handler1.create_access_token(user_id="user_001") - with pytest.raises(Exception): + with pytest.raises(InvalidTokenError): handler2.verify_access_token(token) def test_custom_algorithm(self): diff --git a/tests/unit/test_transition_presets.py b/tests/unit/test_transition_presets.py index d2c2d2d9a..ce2db1f0a 100755 --- a/tests/unit/test_transition_presets.py +++ b/tests/unit/test_transition_presets.py @@ -1,3 +1,5 @@ +from dataclasses import FrozenInstanceError + """transition_presets 领域层单元测试 - 转场预设库""" import pytest @@ -50,7 +52,7 @@ class TestTransitionPreset: def test_frozen_immutable(self): """frozen dataclass 不可修改""" preset = TransitionPreset(id="test", name="测试", category="basic") - with pytest.raises(Exception): + with pytest.raises(FrozenInstanceError): preset.name = "改名" def test_tags_default_empty_list(self): @@ -78,7 +80,7 @@ class TestTransitionPresetLibrary: def test_all_presets_have_required_fields(self): """所有预设都有必填字段""" for preset in TRANSITION_PRESET_LIBRARY: - assert preset.id, f"missing id" + assert preset.id, "missing id" assert preset.name, f"{preset.id} missing name" assert preset.category, f"{preset.id} missing category" assert preset.transition, f"{preset.id} missing transition"