diff --git a/tests/test_srt_processor.py b/tests/test_srt_processor.py index 86ec859..7e5546c 100644 --- a/tests/test_srt_processor.py +++ b/tests/test_srt_processor.py @@ -14,6 +14,7 @@ import pytest from pathlib import Path from dataclasses import dataclass from typing import List, Optional +from unittest.mock import Mock # ============================================================================= @@ -504,74 +505,66 @@ class TestSemanticSegmentationToggle: from kb_workflow.pipeline.processors.srt import SRTProcessor from unittest.mock import patch - with patch('kb_workflow.srt.semantic_engine.SimpleAIClient') as mock_client: + with patch('kb_workflow.deep_analyzer.SimpleAIClient') as mock_client: mock_client.return_value = Mock(api_key="test_key") processor = SRTProcessor( - config={}, enable_semantic_segmentation=True ) # 验证创建了 SemanticSegmentationEngine - assert hasattr(processor, 'semantic_engine') - # 注意:当前实现可能还没有这些属性,这个测试在实现后会通过 - # assert processor.semantic_engine is not None - # assert processor.segmenter is None + from kb_workflow.srt.semantic_engine import SemanticSegmentationEngine + assert isinstance(processor.segmenter, SemanticSegmentationEngine) + # 验证缓存已启用(默认) + assert processor.segmenter.strategy.cache is not None def test_semantic_segmentation_disabled(self, sample_srt_file_for_toggle): """测试禁用语义分段(默认)""" from kb_workflow.pipeline.processors.srt import SRTProcessor + from kb_workflow.srt.segmenter import SemanticSegmenter processor = SRTProcessor( - config={}, enable_semantic_segmentation=False ) # 验证使用规则分段器 - # 注意:当前实现可能还没有这些属性,这个测试在实现后会通过 - # assert processor.semantic_engine is None - # assert processor.segmenter is not None - pass + assert isinstance(processor.segmenter, SemanticSegmenter) def test_semantic_segmentation_with_cache(self, sample_srt_file_for_toggle): """测试启用语义分段和缓存""" from kb_workflow.pipeline.processors.srt import SRTProcessor from unittest.mock import patch - with patch('kb_workflow.srt.semantic_engine.SimpleAIClient') as mock_client: + with patch('kb_workflow.deep_analyzer.SimpleAIClient') as mock_client: mock_client.return_value = Mock(api_key="test_key") processor = SRTProcessor( - config={}, enable_semantic_segmentation=True, enable_cache=True ) - # 验证创建了缓存 - # 注意:当前实现可能还没有这些属性,这个测试在实现后会通过 - # assert processor.semantic_engine is not None - # assert processor.semantic_engine.strategy.cache is not None - pass + # 验证创建了 SemanticSegmentationEngine 且缓存已启用 + from kb_workflow.srt.semantic_engine import SemanticSegmentationEngine + assert isinstance(processor.segmenter, SemanticSegmentationEngine) + assert processor.segmenter.strategy.cache is not None def test_semantic_segmentation_without_cache(self, sample_srt_file_for_toggle): """测试启用语义分段但禁用缓存""" from kb_workflow.pipeline.processors.srt import SRTProcessor from unittest.mock import patch - with patch('kb_workflow.srt.semantic_engine.SimpleAIClient') as mock_client: + with patch('kb_workflow.deep_analyzer.SimpleAIClient') as mock_client: mock_client.return_value = Mock(api_key="test_key") processor = SRTProcessor( - config={}, enable_semantic_segmentation=True, enable_cache=False ) - # 验证没有创建缓存 - # 注意:当前实现可能还没有这些属性,这个测试在实现后会通过 - # assert processor.semantic_engine is not None - # assert processor.semantic_engine.strategy.cache is None - pass + # 验证创建了 SemanticSegmentationEngine 但缓存未启用 + from kb_workflow.srt.semantic_engine import SemanticSegmentationEngine + assert isinstance(processor.segmenter, SemanticSegmentationEngine) + assert processor.segmenter.strategy.cache is None @pytest.fixture def sample_srt_file_for_toggle(self, tmp_path):