File size: 1,596 Bytes
3e848bc d25f40f 3e848bc 5c26975 3e848bc c754d32 3e848bc c754d32 a06172d c754d32 d25f40f 3e848bc f36740b 853b244 3e848bc c754d32 f2a55e2 c754d32 a06172d f2a55e2 c754d32 a06172d c754d32 f2a55e2 c754d32 f2a55e2 f36740b |
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 |
#!/usr/bin/env python
"""Tests for `deep_translator` package."""
import pytest
from deep_translator import exceptions, GoogleTranslator
@pytest.fixture
def google_translator():
"""Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html
"""
return GoogleTranslator(target='en')
def test_content(google_translator):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string
assert google_translator.translate(text='좋은') == "good"
def test_inputs():
with pytest.raises(exceptions.LanguageNotSupportedException):
GoogleTranslator(source="", target="")
with pytest.raises(exceptions.LanguageNotSupportedException):
GoogleTranslator(source="auto", target="nothing")
# test abbreviations and languages
g1 = GoogleTranslator("en", "fr")
g2 = GoogleTranslator("english", "french")
assert g1._source == g2._source
assert g1._target == g2._target
def test_payload(google_translator):
with pytest.raises(exceptions.NotValidPayload):
google_translator.translate(text="")
with pytest.raises(exceptions.NotValidPayload):
google_translator.translate(text=123)
with pytest.raises(exceptions.NotValidPayload):
google_translator.translate(text={})
with pytest.raises(exceptions.NotValidPayload):
google_translator.translate(text=[])
with pytest.raises(exceptions.NotValidLength):
google_translator.translate("a"*5001)
|