=
commited on
Commit
·
97fe725
1
Parent(s):
f2a55e2
added more tests for linguee and mymemory
Browse files
deep_translator/tests/test_linguee.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
"""Tests for `deep_translator` package."""
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
from deep_translator import exceptions, LingueeTranslator
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.fixture
|
| 10 |
+
def linguee():
|
| 11 |
+
return LingueeTranslator(target='fr')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def test_content(linguee):
|
| 15 |
+
"""Sample pytest test function with the pytest fixture as an argument."""
|
| 16 |
+
# from bs4 import BeautifulSoup
|
| 17 |
+
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
| 18 |
+
assert linguee.translate(word='good') is not None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_inputs():
|
| 22 |
+
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 23 |
+
linguee(source="", target="")
|
| 24 |
+
|
| 25 |
+
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 26 |
+
linguee(source="auto", target="nothing")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_payload(linguee):
|
| 30 |
+
|
| 31 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 32 |
+
linguee.translate("")
|
| 33 |
+
|
| 34 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 35 |
+
linguee.translate(123)
|
| 36 |
+
|
| 37 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 38 |
+
linguee.translate({})
|
| 39 |
+
|
| 40 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 41 |
+
linguee.translate([])
|
deep_translator/tests/test_mymemory.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
|
| 3 |
+
"""Tests for `deep_translator` package."""
|
| 4 |
+
|
| 5 |
+
import pytest
|
| 6 |
+
from deep_translator import exceptions, GoogleTranslator, MyMemoryTranslator
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.fixture
|
| 10 |
+
def mymemory():
|
| 11 |
+
return MyMemoryTranslator(target='fr')
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def test_content(mymemory):
|
| 15 |
+
"""Sample pytest test function with the pytest fixture as an argument."""
|
| 16 |
+
# from bs4 import BeautifulSoup
|
| 17 |
+
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
| 18 |
+
assert mymemory.translate(text='good') is not None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_inputs():
|
| 22 |
+
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 23 |
+
mymemory(source="", target="")
|
| 24 |
+
|
| 25 |
+
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 26 |
+
mymemory(source="auto", target="nothing")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def test_payload(mymemory):
|
| 30 |
+
|
| 31 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 32 |
+
mymemory.translate(text="")
|
| 33 |
+
|
| 34 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 35 |
+
mymemory.translate(text=123)
|
| 36 |
+
|
| 37 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 38 |
+
mymemory.translate(text={})
|
| 39 |
+
|
| 40 |
+
with pytest.raises(exceptions.NotValidPayload):
|
| 41 |
+
mymemory.translate(text=[])
|