461bf6fd40
CI / lint (3.11) (push) Blocked by required conditions
CI / lint (3.12) (push) Blocked by required conditions
CI / lint (3.13) (push) Blocked by required conditions
CI / shellcheck (push) Waiting to run
CI / shfmt (push) Waiting to run
CI / setup (3.11) (push) Waiting to run
CI / setup (3.12) (push) Waiting to run
CI / setup (3.13) (push) Waiting to run
CI / check-licenses (3.12) (push) Blocked by required conditions
CI / test_unit (3.11) (push) Blocked by required conditions
CI / test_unit (3.12) (push) Blocked by required conditions
CI / test_unit (3.13) (push) Blocked by required conditions
CI / test_unit_no_extras (3.11) (push) Blocked by required conditions
CI / test_unit_no_extras (3.12) (push) Blocked by required conditions
CI / test_json_to_html (3.12) (push) Blocked by required conditions
CI / test_unit_no_extras (3.13) (push) Blocked by required conditions
CI / test_unit_dependency_extras (csv, 3.11, --extra csv) (push) Blocked by required conditions
CI / test_unit_dependency_extras (csv, 3.12, --extra csv) (push) Blocked by required conditions
CI / test_unit_dependency_extras (csv, 3.13, --extra csv) (push) Blocked by required conditions
CI / test_unit_dependency_extras (docx, 3.11, --extra docx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (docx, 3.12, --extra docx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (docx, 3.13, --extra docx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (markdown, 3.11, --extra md) (push) Blocked by required conditions
CI / test_unit_dependency_extras (markdown, 3.12, --extra md) (push) Blocked by required conditions
CI / test_unit_dependency_extras (markdown, 3.13, --extra md) (push) Blocked by required conditions
CI / test_unit_dependency_extras (odt, 3.11, --extra odt) (push) Blocked by required conditions
CI / test_unit_dependency_extras (odt, 3.12, --extra odt) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pdf-image, 3.12, --extra pdf --extra image --extra paddleocr) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pdf-image, 3.13, --extra pdf --extra image --extra paddleocr) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pptx, 3.13, --extra pptx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (odt, 3.13, --extra odt) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pdf-image, 3.11, --extra pdf --extra image --extra paddleocr) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pptx, 3.11, --extra pptx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pptx, 3.12, --extra pptx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pypandoc, 3.11, --extra epub --extra org --extra rtf --extra rst) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pypandoc, 3.12, --extra epub --extra org --extra rtf --extra rst) (push) Blocked by required conditions
CI / test_unit_dependency_extras (pypandoc, 3.13, --extra epub --extra org --extra rtf --extra rst) (push) Blocked by required conditions
CI / test_unit_dependency_extras (xlsx, 3.11, --extra xlsx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (xlsx, 3.12, --extra xlsx) (push) Blocked by required conditions
CI / test_unit_dependency_extras (xlsx, 3.13, --extra xlsx) (push) Blocked by required conditions
CI / test_ingest_src (3.12) (push) Blocked by required conditions
CI / test_json_to_markdown (3.12) (push) Blocked by required conditions
CI / changelog (push) Waiting to run
CI / test_dockerfile (push) Blocked by required conditions
CodeQL / Analyze (python) (push) Waiting to run
Build And Push Docker Image / set-short-sha (push) Waiting to run
Build And Push Docker Image / build-images (linux/amd64, opensource-linux-8core) (push) Blocked by required conditions
Build And Push Docker Image / build-images (linux/arm64, ubuntu-24.04-arm) (push) Blocked by required conditions
Build And Push Docker Image / publish-images (push) Blocked by required conditions
Partition Benchmark / setup (push) Waiting to run
Partition Benchmark / Measure and compare partition() runtime (push) Blocked by required conditions
65 lines
2.0 KiB
Python
65 lines
2.0 KiB
Python
import os
|
|
|
|
import pytest
|
|
|
|
from unstructured.cleaners import translate
|
|
|
|
IS_CI = os.getenv("CI") == "true"
|
|
|
|
|
|
def test_get_opus_mt_model_name():
|
|
model_name = translate._get_opus_mt_model_name("ru", "en")
|
|
assert model_name == "Helsinki-NLP/opus-mt-ru-en"
|
|
|
|
|
|
@pytest.mark.parametrize("code", ["way-too-long", "a", "", None])
|
|
def test_validate_language_code(code):
|
|
with pytest.raises(ValueError):
|
|
translate._validate_language_code(code)
|
|
|
|
|
|
def test_translate_returns_same_text_if_dest_is_same():
|
|
text = "This is already in English!"
|
|
assert translate.translate_text(text, "en", "en") == text
|
|
|
|
|
|
def test_translate_returns_same_text_text_is_empty():
|
|
text = " "
|
|
assert translate.translate_text(text) == text
|
|
|
|
|
|
@pytest.mark.skipif(IS_CI, reason="Skipping this test in CI pipeline")
|
|
def test_translate_with_language_specified():
|
|
text = "Ich bin ein Berliner!"
|
|
assert translate.translate_text(text, "de") == "I'm a Berliner!"
|
|
|
|
|
|
@pytest.mark.skipif(IS_CI, reason="Skipping this test in CI pipeline")
|
|
def test_translate_with_no_language_specified():
|
|
text = "Ich bin ein Berliner!"
|
|
assert translate.translate_text(text) == "I'm a Berliner!"
|
|
|
|
|
|
@pytest.mark.skipif(IS_CI, reason="Skipping this test in CI pipeline")
|
|
def test_translate_raises_with_bad_language():
|
|
text = "Ich bin ein Berliner!"
|
|
with pytest.raises(ValueError):
|
|
translate.translate_text(text, "zz")
|
|
|
|
|
|
@pytest.mark.skipif(IS_CI, reason="Skipping this test in CI pipeline")
|
|
def test_tranlate_works_with_russian():
|
|
text = "Я тоже можно переводать русский язык!"
|
|
assert translate.translate_text(text) == "I can also translate Russian!"
|
|
|
|
|
|
@pytest.mark.skipif(IS_CI, reason="Skipping this test in CI pipeline")
|
|
def test_translate_works_with_chinese():
|
|
text = "網站有中、英文版本"
|
|
translate.translate_text(text) == "Website available in Chinese and English"
|
|
|
|
|
|
def translate_works_with_arabic():
|
|
text = "مرحباً بكم في متجرنا"
|
|
translate.translate_text(text) == "Welcome to our store."
|