File size: 1,513 Bytes
8ecada8 b1c7fbf 8ecada8 5a13ae6 8ecada8 5a13ae6 a1efbe8 8ecada8 f36740b 8ecada8 f36740b 3eb36f5 2cefccb 3eb36f5 2cefccb a27ea01 |
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!/usr/bin/env python
"""Tests for `deep_translator` package."""
import pytest
from deep_translator import exceptions, PonsTranslator
@pytest.fixture
def pons():
return PonsTranslator(source="english", target='french')
def test_content(pons):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string
assert pons.translate(word='good') is not None
def test_inputs():
with pytest.raises(exceptions.LanguageNotSupportedException):
PonsTranslator(source="", target="")
with pytest.raises(exceptions.LanguageNotSupportedException):
PonsTranslator(source="auto", target="nothing")
l1 = PonsTranslator("en", "fr")
l2 = PonsTranslator("english", "french")
assert l1._source == l2._source
assert l1._target == l2._target
def test_payload(pons):
with pytest.raises(exceptions.NotValidPayload):
pons.translate("")
with pytest.raises(exceptions.NotValidPayload):
pons.translate(123)
with pytest.raises(exceptions.NotValidPayload):
pons.translate({})
with pytest.raises(exceptions.NotValidPayload):
pons.translate([])
with pytest.raises(exceptions.NotValidLength):
pons.translate("a" * 51)
def test_translate_words(pons):
words = ['hello', 'world']
translated_words = pons.translate_words(words)
def test_one_character_words(pons):
assert pons.translate('I')
|