ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Test suite locking out ZeroDivisionError in EmbeddingService.encode_batch
|
||||
when an empty texts list is provided.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
# Mock third-party dependencies before importing embedding_service
|
||||
sys.modules['FlagEmbedding'] = MagicMock()
|
||||
sys.modules['colorlog'] = MagicMock()
|
||||
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
|
||||
|
||||
from embedding_service import EmbeddingService
|
||||
|
||||
|
||||
def test_encode_batch_empty_texts_logger_zero_division():
|
||||
"""
|
||||
Ensure encode_batch with an empty list of texts does not raise ZeroDivisionError
|
||||
during logging.
|
||||
"""
|
||||
service = EmbeddingService.__new__(EmbeddingService)
|
||||
mock_logger = MagicMock()
|
||||
service.logger = mock_logger
|
||||
service.model = MagicMock()
|
||||
service.model.encode.return_value = {
|
||||
'dense_vecs': MagicMock(shape=(0, 768))
|
||||
}
|
||||
|
||||
result = service.encode_batch([])
|
||||
assert result['num_texts'] == 0
|
||||
assert result['dimension'] == 768
|
||||
Reference in New Issue
Block a user