mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-05 05:16:03 +00:00
- Add test_handler_helpers.py for plugin handler helpers (7 tests) - Add test_mgr_methods.py for persistence manager (5 tests) - Add test_app_config_validation.py for core app config (12 tests) - Add test_knowledge_service.py for API knowledge service (22 tests) - Add test_kbmgr.py for RAG knowledge base manager (39 tests) - Add test_survey_manager.py for survey manager (22 tests) - Add test_connector_methods.py for plugin connector (24 tests) - Add test_funcschema.py for utils function schema (9 tests) - Add test_platform.py for utils platform detection (7 tests) - Add test_extract_deps.py for plugin deps extraction (7 tests) - Add test_database_decorator.py for persistence decorator (7 tests) - Add test_load_config.py for core config loading (19 tests) - Add COVERAGE_EXCLUSIONS.md documenting external adapter exclusions - Fix test_chat_session_limit.py path for portability Coverage: core 28% → 30%, persistence 24% → 24.4%, plugin 27% → 28% Total: 1082 tests passed, core module coverage 45.5% Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
"""Unit tests for RAG i18n name conversion.
|
|
|
|
Tests cover:
|
|
- _to_i18n_name() static method
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from importlib import import_module
|
|
|
|
|
|
def get_kbmgr_module():
|
|
"""Lazy import to avoid circular import issues."""
|
|
return import_module('langbot.pkg.rag.knowledge.kbmgr')
|
|
|
|
|
|
class TestToI18nName:
|
|
"""Tests for _to_i18n_name static method."""
|
|
|
|
def test_string_input_wrapped(self):
|
|
"""Test that string input is wrapped into i18n dict."""
|
|
kbmgr = get_kbmgr_module()
|
|
result = kbmgr.RAGManager._to_i18n_name('Test Engine')
|
|
assert result == {'en_US': 'Test Engine', 'zh_Hans': 'Test Engine'}
|
|
|
|
def test_dict_input_preserved(self):
|
|
"""Test that dict input is returned as-is."""
|
|
kbmgr = get_kbmgr_module()
|
|
input_dict = {'en_US': 'English Name', 'zh_Hans': '中文名', 'ja_JP': '日本語名'}
|
|
result = kbmgr.RAGManager._to_i18n_name(input_dict)
|
|
assert result == input_dict
|
|
assert result is input_dict # Should return the same object
|
|
|
|
def test_empty_string_handling(self):
|
|
"""Test that empty string is handled correctly."""
|
|
kbmgr = get_kbmgr_module()
|
|
result = kbmgr.RAGManager._to_i18n_name('')
|
|
assert result == {'en_US': '', 'zh_Hans': ''}
|
|
|
|
def test_none_input_handling(self):
|
|
"""Test that None is converted to string 'None'."""
|
|
kbmgr = get_kbmgr_module()
|
|
result = kbmgr.RAGManager._to_i18n_name(None)
|
|
assert result == {'en_US': 'None', 'zh_Hans': 'None'}
|
|
|
|
def test_number_input_converted_to_string(self):
|
|
"""Test that numbers are converted to strings."""
|
|
kbmgr = get_kbmgr_module()
|
|
result = kbmgr.RAGManager._to_i18n_name(123)
|
|
assert result == {'en_US': '123', 'zh_Hans': '123'}
|
|
|
|
def test_dict_with_partial_keys_preserved(self):
|
|
"""Test that dict with only some i18n keys is preserved."""
|
|
kbmgr = get_kbmgr_module()
|
|
input_dict = {'en_US': 'Only English'}
|
|
result = kbmgr.RAGManager._to_i18n_name(input_dict)
|
|
assert result == {'en_US': 'Only English'}
|
|
|
|
def test_dict_with_extra_keys_preserved(self):
|
|
"""Test that dict with extra non-i18n keys is preserved."""
|
|
kbmgr = get_kbmgr_module()
|
|
input_dict = {'en_US': 'English', 'extra_key': 'extra_value'}
|
|
result = kbmgr.RAGManager._to_i18n_name(input_dict)
|
|
assert result == {'en_US': 'English', 'extra_key': 'extra_value'} |