test_translate.py 1002 B

1234567891011121314151617181920212223242526272829
  1. from app.core.llm.llm_service import (
  2. fallback_translate_chinese,
  3. is_valid_translation,
  4. normalize_translation_text,
  5. translate_chinese_identifier,
  6. )
  7. def test_normalize_translation_text_strips_chinese():
  8. assert normalize_translation_text("测试宁波数据加工") == ""
  9. assert normalize_translation_text('"Ningbo Data Processing"') == "ningbo_data_processing"
  10. def test_fallback_translate_ningbo_data_processing():
  11. result = fallback_translate_chinese("测试宁波数据加工")
  12. assert result == "ningbo_data_processing_test"
  13. assert is_valid_translation(result)
  14. def test_translate_chinese_identifier_uses_fallback_when_llm_unavailable(monkeypatch):
  15. def _raise(*args, **kwargs):
  16. raise ValueError("DeepSeek API Key 未配置")
  17. monkeypatch.setattr(
  18. "app.core.llm.llm_service.create_llm_client",
  19. _raise,
  20. )
  21. result = translate_chinese_identifier("测试宁波数据加工")
  22. assert result == "ningbo_data_processing_test"