omi icon indicating copy to clipboard operation
omi copied to clipboard

Read translation optimization source tests as UTF-8

Open tianmind-studio opened this issue 5 months ago • 1 comments

Summary

  • Read transcribe.py and translation_coordinator.py source snapshots as UTF-8 in test_translation_optimization.py.
  • Fix Windows non-UTF-8 locale failures in the translation persistence guard source tests.
  • Keep the existing translation optimization assertions unchanged.

Windows reproduction

Before this change on Windows with the default GBK locale:

  • python -m pytest tests\unit\test_translation_optimization.py -q -> 2 failed, 90 passed
  • failures were UnicodeDecodeError: 'gbk' codec can't decode byte ... while reading routers/transcribe.py and utils/translation_coordinator.py

Testing

  • python -m pytest tests\unit\test_translation_optimization.py -q -> 92 passed
  • python -m black --line-length 120 --skip-string-normalization tests\unit\test_translation_optimization.py --check
  • python -m py_compile tests\unit\test_translation_optimization.py
  • git diff --check origin/main...HEAD

tianmind-studio avatar Jun 10 '26 08:06 tianmind-studio

Greptile Summary

This PR adds encoding='utf-8' to three open() calls in test_translation_optimization.py that read Python source files (routers/transcribe.py and utils/translation_coordinator.py) as text. Without this, the tests would fail with UnicodeDecodeError on Windows systems whose default locale uses a non-UTF-8 codec (e.g., GBK).

  • Adds encoding='utf-8' to all three open() calls that read source files in TestTranslateSegmentGuardWired, fixing Windows locale failures.
  • No test logic or assertions are changed — this is a pure compatibility fix.

Confidence Score: 5/5

Safe to merge — the change is a three-line encoding fix in a test file with no impact on production code.

The change exclusively adds encoding='utf-8' to file-read calls in tests. All three relevant open() calls in the file now carry the explicit encoding; no test logic or assertions were altered. The fix is portable and correct.

No files require special attention.

Important Files Changed

Filename Overview
backend/tests/unit/test_translation_optimization.py Adds encoding='utf-8' to all three source-file open() calls in TestTranslateSegmentGuardWired; no other logic changes.

Reviews (1): Last reviewed commit: "Read translation optimization source tes..." | Re-trigger Greptile

greptile-apps avatar Jun 10 '26 08:06 greptile-apps