File size: 1,186 Bytes
9a69d6b 7a05cd7 76aa3b2 50c16a8 a8c6e0d 9a69d6b 78d0ff1 9a69d6b a8c6e0d 9a69d6b 4524f4c 78d0ff1 9a69d6b 4524f4c 78d0ff1 4524f4c 78d0ff1 9a69d6b a8c6e0d 50c16a8 76aa3b2 4524f4c 9a69d6b a8c6e0d 9a69d6b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#!/usr/bin/env python
"""Tests for `deep_translator` package."""
import pytest
from deep_translator import LibreTranslator, exceptions
from deep_translator.constants import LIBRE_LANGUAGES_TO_CODES
@pytest.fixture
def libre():
return LibreTranslator(source="en", target="fr", api_key="some_key")
def test_inputs():
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
LibreTranslator(source="", target="", api_key="some_key")
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
LibreTranslator(source="auto", target="", api_key="some_key")
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
LibreTranslator(source="", target="en", api_key="some_key")
def test_abbreviations_and_languages_mapping():
for abb, lang in LIBRE_LANGUAGES_TO_CODES.items():
l1 = LibreTranslator(source=abb, api_key="some_key")
l2 = LibreTranslator(source=lang, api_key="some_key")
assert l1._source == l2._source
def test_payload(libre):
with pytest.raises(exceptions.NotValidPayload):
libre.translate({})
with pytest.raises(exceptions.NotValidPayload):
libre.translate([])
|