nidhal baccouri
commited on
Commit
·
4524f4c
1
Parent(s):
f89616a
refactored tests
Browse files- deep_translator/base.py +6 -0
- deep_translator/exceptions.py +1 -2
- tests/test_google.py +68 -0
- tests/test_google_trans.py +0 -175
- tests/test_libre.py +9 -33
- tests/test_linguee.py +6 -15
- tests/test_microsoft_trans.py +2 -2
- tests/test_mymemory.py +7 -6
- tests/test_pons.py +7 -15
deep_translator/base.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
"""base translator class"""
|
2 |
|
3 |
from .constants import GOOGLE_LANGUAGES_TO_CODES
|
|
|
4 |
from abc import ABC, abstractmethod
|
5 |
|
6 |
|
@@ -24,6 +25,11 @@ class BaseTranslator(ABC):
|
|
24 |
self._base_url = base_url
|
25 |
self.languages: dict = GOOGLE_LANGUAGES_TO_CODES if not languages else languages
|
26 |
self.supported_languages: list = list(self.languages.keys())
|
|
|
|
|
|
|
|
|
|
|
27 |
self._source, self._target = self._map_language_to_code(source, target)
|
28 |
self._url_params = url_params
|
29 |
self._element_tag = element_tag
|
|
|
1 |
"""base translator class"""
|
2 |
|
3 |
from .constants import GOOGLE_LANGUAGES_TO_CODES
|
4 |
+
from .exceptions import InvalidSourceOrTargetLanguage
|
5 |
from abc import ABC, abstractmethod
|
6 |
|
7 |
|
|
|
25 |
self._base_url = base_url
|
26 |
self.languages: dict = GOOGLE_LANGUAGES_TO_CODES if not languages else languages
|
27 |
self.supported_languages: list = list(self.languages.keys())
|
28 |
+
if not source:
|
29 |
+
raise InvalidSourceOrTargetLanguage(source)
|
30 |
+
if not target:
|
31 |
+
raise InvalidSourceOrTargetLanguage(target)
|
32 |
+
|
33 |
self._source, self._target = self._map_language_to_code(source, target)
|
34 |
self._url_params = url_params
|
35 |
self._element_tag = element_tag
|
deep_translator/exceptions.py
CHANGED
@@ -43,11 +43,10 @@ class InvalidSourceOrTargetLanguage(BaseError):
|
|
43 |
|
44 |
def __init__(self,
|
45 |
val,
|
46 |
-
message="source
|
47 |
super(InvalidSourceOrTargetLanguage, self).__init__(val, message)
|
48 |
|
49 |
|
50 |
-
|
51 |
class TranslationNotFound(BaseError):
|
52 |
"""
|
53 |
exception thrown if no translation was found for the text provided by the user
|
|
|
43 |
|
44 |
def __init__(self,
|
45 |
val,
|
46 |
+
message="Invalid source or target language!"):
|
47 |
super(InvalidSourceOrTargetLanguage, self).__init__(val, message)
|
48 |
|
49 |
|
|
|
50 |
class TranslationNotFound(BaseError):
|
51 |
"""
|
52 |
exception thrown if no translation was found for the text provided by the user
|
tests/test_google.py
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
"""Tests for `deep_translator` package."""
|
4 |
+
|
5 |
+
import pytest
|
6 |
+
from deep_translator import exceptions, GoogleTranslator
|
7 |
+
from deep_translator.constants import GOOGLE_CODES_TO_LANGUAGES
|
8 |
+
|
9 |
+
|
10 |
+
@pytest.fixture
|
11 |
+
def google_translator():
|
12 |
+
"""Sample pytest fixture.
|
13 |
+
See more at: http://doc.pytest.org/en/latest/fixture.html
|
14 |
+
"""
|
15 |
+
return GoogleTranslator(target='en')
|
16 |
+
|
17 |
+
|
18 |
+
def test_content(google_translator):
|
19 |
+
"""Sample pytest test function with the pytest fixture as an argument."""
|
20 |
+
assert google_translator.translate(text='좋은') == "good"
|
21 |
+
|
22 |
+
|
23 |
+
def test_abbreviations_and_languages_mapping():
|
24 |
+
for abb, lang in GOOGLE_CODES_TO_LANGUAGES.items():
|
25 |
+
g1 = GoogleTranslator(abb)
|
26 |
+
g2 = GoogleTranslator(lang)
|
27 |
+
assert g1._source == g2._source
|
28 |
+
|
29 |
+
|
30 |
+
def test_inputs():
|
31 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
32 |
+
GoogleTranslator(source="", target="")
|
33 |
+
|
34 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
35 |
+
GoogleTranslator(source="auto", target="")
|
36 |
+
|
37 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
38 |
+
GoogleTranslator(source="", target="en")
|
39 |
+
|
40 |
+
|
41 |
+
def test_empty_text(google_translator):
|
42 |
+
empty_txt = ""
|
43 |
+
res = google_translator.translate(text=empty_txt)
|
44 |
+
assert res == empty_txt
|
45 |
+
|
46 |
+
|
47 |
+
def test_payload(google_translator):
|
48 |
+
|
49 |
+
with pytest.raises(exceptions.NotValidPayload):
|
50 |
+
google_translator.translate(text='1234')
|
51 |
+
google_translator.translate(text='{}')
|
52 |
+
google_translator.translate(text='%@')
|
53 |
+
|
54 |
+
with pytest.raises(exceptions.NotValidPayload):
|
55 |
+
google_translator.translate(text=123)
|
56 |
+
|
57 |
+
with pytest.raises(exceptions.NotValidPayload):
|
58 |
+
google_translator.translate(text={})
|
59 |
+
|
60 |
+
with pytest.raises(exceptions.NotValidPayload):
|
61 |
+
google_translator.translate(text=[])
|
62 |
+
|
63 |
+
with pytest.raises(exceptions.NotValidLength):
|
64 |
+
google_translator.translate("a"*5001)
|
65 |
+
|
66 |
+
|
67 |
+
def test_one_character_words():
|
68 |
+
assert GoogleTranslator(source='es', target='en').translate('o') == 'or'
|
tests/test_google_trans.py
DELETED
@@ -1,175 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python
|
2 |
-
|
3 |
-
"""Tests for `deep_translator` package."""
|
4 |
-
|
5 |
-
import pytest
|
6 |
-
from deep_translator import exceptions, GoogleTranslator
|
7 |
-
from deep_translator.constants import GOOGLE_CODES_TO_LANGUAGES
|
8 |
-
|
9 |
-
|
10 |
-
test_text_standard = 'Hello world.'
|
11 |
-
|
12 |
-
TRANSLATED_RESULTS = {
|
13 |
-
"afrikaans": "Hello Wêreld.",
|
14 |
-
"albanian": "Përshendetje Botë.",
|
15 |
-
"amharic": "ሰላም ልዑል.",
|
16 |
-
"arabic": "مرحبا بالعالم.",
|
17 |
-
"armenian": "Բարեւ աշխարհ.",
|
18 |
-
"azerbaijani": "Salam dünya.",
|
19 |
-
"basque": "Kaixo Mundua.",
|
20 |
-
"belarusian": "Прывітанне Сусвет.",
|
21 |
-
"bengali": "ওহে বিশ্ব.",
|
22 |
-
"bosnian": "Zdravo svijete.",
|
23 |
-
"bulgarian": "Здравей свят.",
|
24 |
-
"catalan": "Hola món.",
|
25 |
-
"cebuano": "Kumusta kalibutan.",
|
26 |
-
"chichewa": "Moni Dziko Lapansi.",
|
27 |
-
"chinese (simplified)": "你好,世界。",
|
28 |
-
"chinese (traditional)": "你好,世界。",
|
29 |
-
"corsican": "Bonghjornu mondu.",
|
30 |
-
"croatian": "Pozdrav svijete.",
|
31 |
-
"czech": "Ahoj světe.",
|
32 |
-
"danish": "Hej Verden.",
|
33 |
-
"dutch": "Hallo Wereld.",
|
34 |
-
"esperanto": "Saluton mondo.",
|
35 |
-
"estonian": "Tere, Maailm.",
|
36 |
-
"filipino": "Kamusta mundo",
|
37 |
-
"finnish": "Hei maailma.",
|
38 |
-
"french": "Bonjour le monde.",
|
39 |
-
"frisian": "Hallo wrâld.",
|
40 |
-
"galician": "Ola mundo.",
|
41 |
-
"georgian": "Გამარჯობა მსოფლიო.",
|
42 |
-
"german": "Hallo Welt.",
|
43 |
-
"greek": "Γειά σου Κόσμε.",
|
44 |
-
"gujarati": "હેલો વર્લ્ડ.",
|
45 |
-
"haitian creole": "Bonjou mond.",
|
46 |
-
"hausa": "Sannu Duniya.",
|
47 |
-
"hawaiian": "Aloha honua.",
|
48 |
-
"hebrew": "שלום עולם.",
|
49 |
-
"hindi": "नमस्ते दुनिया।",
|
50 |
-
"hmong": "Nyob zoo ntiaj teb.",
|
51 |
-
"hungarian": "Helló Világ.",
|
52 |
-
"icelandic": "Halló heimur.",
|
53 |
-
"igbo": "Ndewo Ụwa.",
|
54 |
-
"indonesian": "Halo Dunia.",
|
55 |
-
"irish": "Dia duit ar domhan.",
|
56 |
-
"italian": "Ciao mondo.",
|
57 |
-
"japanese": "こんにちは世界。",
|
58 |
-
"javanese": "Halo jagad.",
|
59 |
-
"kannada": "ಹಲೋ ವಿಶ್ವ.",
|
60 |
-
"kazakh": "Сәлем Әлем.",
|
61 |
-
"khmer": "សួស្តីពិភពលោក។",
|
62 |
-
"kinyarwanda": "Mwaramutse isi.",
|
63 |
-
"korean": "안녕하세요 세계입니다.",
|
64 |
-
"kurdish": "Hello cîhanê.",
|
65 |
-
"kyrgyz": "Салам дүйнө.",
|
66 |
-
"lao": "ສະບາຍດີຊາວໂລກ.",
|
67 |
-
"latin": "Salve mundi.",
|
68 |
-
"latvian": "Sveika pasaule.",
|
69 |
-
"lithuanian": "Labas pasauli.",
|
70 |
-
"luxembourgish": "Moien Welt.",
|
71 |
-
"macedonian": "Здраво свету.",
|
72 |
-
"malagasy": "Hello World.",
|
73 |
-
"malay": "Hai dunia.",
|
74 |
-
"malayalam": "ഹലോ വേൾഡ്.",
|
75 |
-
"maltese": "Hello dinja.",
|
76 |
-
"maori": "Kia ora te ao.",
|
77 |
-
"marathi": "नमस्कार जग.",
|
78 |
-
"mongolian": "Сайн уу ертөнц.",
|
79 |
-
"myanmar": "မင်္ဂလာပါကမ္ဘာလောက။",
|
80 |
-
"nepali": "नमस्कार संसार।",
|
81 |
-
"norwegian": "Hei Verden.",
|
82 |
-
"odia": "ନମସ୍କାର ବିଶ୍ୱବାସି।",
|
83 |
-
"pashto": "سلام نړی.",
|
84 |
-
"persian": "سلام دنیا.",
|
85 |
-
"polish": "Witaj świecie.",
|
86 |
-
"portuguese": "Olá Mundo.",
|
87 |
-
"punjabi": "ਸਤਿ ਸ੍ਰੀ ਅਕਾਲ ਦੁਨਿਆ.",
|
88 |
-
"romanian": "Salut Lume.",
|
89 |
-
"russian": "Привет, мир.",
|
90 |
-
"samoan": "Talofa lalolagi.",
|
91 |
-
"scots gaelic": "Hàlo a Shaoghail.",
|
92 |
-
"serbian": "Здраво Свете.",
|
93 |
-
"sesotho": "Lefatše Lumela.",
|
94 |
-
"shona": "Mhoro nyika.",
|
95 |
-
"sindhi": "هيلو دنيا.",
|
96 |
-
"sinhala": "හෙලෝ වර්ල්ඩ්.",
|
97 |
-
"slovak": "Ahoj svet.",
|
98 |
-
"slovenian": "Pozdravljen, svet.",
|
99 |
-
"somali": "Salaamu calaykum.",
|
100 |
-
"spanish": "Hola Mundo.",
|
101 |
-
"sundanese": "Halo Dunya.",
|
102 |
-
"swahili": "Salamu, Dunia.",
|
103 |
-
"swedish": "Hej världen.",
|
104 |
-
"tajik": "Салом Ҷаҳон.",
|
105 |
-
"tamil": "வணக்கம் உலகம்.",
|
106 |
-
"tatar": "Сәлам, Дөнья.",
|
107 |
-
"telugu": "హలో వరల్డ్.",
|
108 |
-
"thai": "สวัสดีชาวโลก.",
|
109 |
-
"turkish": "Selam Dünya.",
|
110 |
-
"turkmen": "Salam dünýä.",
|
111 |
-
"ukrainian": "Привіт Світ.",
|
112 |
-
"urdu": "سلام دنیا۔",
|
113 |
-
"uyghur": "ياخشىمۇسىز دۇنيا.",
|
114 |
-
"uzbek": "Salom Dunyo.",
|
115 |
-
"vietnamese": "Chào thế giới.",
|
116 |
-
"welsh": "Helo Byd.",
|
117 |
-
"xhosa": "Molo Lizwe.",
|
118 |
-
"yiddish": "העלא וועלט.",
|
119 |
-
"yoruba": "Mo ki O Ile Aiye.",
|
120 |
-
"zulu": "Sawubona Mhlaba."
|
121 |
-
}
|
122 |
-
|
123 |
-
|
124 |
-
@pytest.fixture
|
125 |
-
def google_translator():
|
126 |
-
"""Sample pytest fixture.
|
127 |
-
See more at: http://doc.pytest.org/en/latest/fixture.html
|
128 |
-
"""
|
129 |
-
return GoogleTranslator(target='en')
|
130 |
-
|
131 |
-
|
132 |
-
def test_content(google_translator):
|
133 |
-
"""Sample pytest test function with the pytest fixture as an argument."""
|
134 |
-
# from bs4 import BeautifulSoup
|
135 |
-
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
136 |
-
assert google_translator.translate(text='좋은') == "good"
|
137 |
-
|
138 |
-
|
139 |
-
def test_abbreviations_and_languages_mapping():
|
140 |
-
for abb, lang in GOOGLE_CODES_TO_LANGUAGES.items():
|
141 |
-
if abb != 'en':
|
142 |
-
g1 = GoogleTranslator(abb)
|
143 |
-
g2 = GoogleTranslator(lang)
|
144 |
-
assert g1._source == g2._source
|
145 |
-
|
146 |
-
|
147 |
-
def test_inputs():
|
148 |
-
with pytest.raises(exceptions.LanguageNotSupportedException):
|
149 |
-
GoogleTranslator(source="", target="")
|
150 |
-
|
151 |
-
with pytest.raises(exceptions.LanguageNotSupportedException):
|
152 |
-
GoogleTranslator(source="auto", target="nothing")
|
153 |
-
|
154 |
-
def test_payload(google_translator):
|
155 |
-
|
156 |
-
with pytest.raises(exceptions.NotValidPayload):
|
157 |
-
google_translator.translate(text="")
|
158 |
-
google_translator.translate(text='1234')
|
159 |
-
google_translator.translate(text='{}')
|
160 |
-
google_translator.translate(text='%@')
|
161 |
-
|
162 |
-
with pytest.raises(exceptions.NotValidPayload):
|
163 |
-
google_translator.translate(text=123)
|
164 |
-
|
165 |
-
with pytest.raises(exceptions.NotValidPayload):
|
166 |
-
google_translator.translate(text={})
|
167 |
-
|
168 |
-
with pytest.raises(exceptions.NotValidPayload):
|
169 |
-
google_translator.translate(text=[])
|
170 |
-
|
171 |
-
with pytest.raises(exceptions.NotValidLength):
|
172 |
-
google_translator.translate("a"*5001)
|
173 |
-
|
174 |
-
def test_one_character_words():
|
175 |
-
assert GoogleTranslator(source='es', target='en').translate('o') == 'or'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_libre.py
CHANGED
@@ -6,27 +6,6 @@ import pytest
|
|
6 |
from deep_translator import exceptions, LibreTranslator
|
7 |
from deep_translator.constants import LIBRE_CODES_TO_LANGUAGES
|
8 |
|
9 |
-
test_text_standard = 'Hello world.'
|
10 |
-
TRANSLATED_RESULTS = {
|
11 |
-
'English': 'Hello world.',
|
12 |
-
'Arabic': 'مرحبا العالم.',
|
13 |
-
'Chinese': '霍洛美世界。',
|
14 |
-
'French': 'Bonjour.',
|
15 |
-
'German': 'Hallo Welt.',
|
16 |
-
'Hindi': 'नमस्ते दुनिया।',
|
17 |
-
'Indonesian': 'Halo dunia.',
|
18 |
-
'Irish': 'Dia duit domhan.',
|
19 |
-
'Italian': 'Ciao mondo.',
|
20 |
-
'Japanese': 'こんにちは。',
|
21 |
-
'Korean': '안녕하세요.',
|
22 |
-
'Polish': 'Hello world (ang.).',
|
23 |
-
'Portuguese': 'Olá, mundo.',
|
24 |
-
'Russian': 'Привет мир.',
|
25 |
-
'Spanish': 'Hola mundo.',
|
26 |
-
'Turkish': 'Merhaba dünya.',
|
27 |
-
'Vietnamese': 'Xin chào.'
|
28 |
-
}
|
29 |
-
|
30 |
|
31 |
@pytest.fixture
|
32 |
def libre():
|
@@ -35,31 +14,28 @@ def libre():
|
|
35 |
|
36 |
def test_content(libre):
|
37 |
"""Sample pytest test function with the pytest fixture as an argument."""
|
38 |
-
# from bs4 import BeautifulSoup
|
39 |
-
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
40 |
assert libre.translate(text='good') is not None
|
41 |
|
42 |
|
43 |
def test_inputs():
|
44 |
-
with pytest.raises(exceptions.
|
45 |
LibreTranslator(source="", target="")
|
46 |
|
47 |
-
with pytest.raises(exceptions.
|
48 |
-
LibreTranslator(source="auto", target="
|
|
|
|
|
|
|
49 |
|
50 |
|
51 |
def test_abbreviations_and_languages_mapping():
|
52 |
for abb, lang in LIBRE_CODES_TO_LANGUAGES.items():
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
assert l1.source == l2.source
|
57 |
|
58 |
|
59 |
def test_payload(libre):
|
60 |
-
with pytest.raises(exceptions.NotValidPayload):
|
61 |
-
libre.translate("")
|
62 |
-
|
63 |
with pytest.raises(exceptions.NotValidPayload):
|
64 |
libre.translate(123)
|
65 |
|
|
|
6 |
from deep_translator import exceptions, LibreTranslator
|
7 |
from deep_translator.constants import LIBRE_CODES_TO_LANGUAGES
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
@pytest.fixture
|
11 |
def libre():
|
|
|
14 |
|
15 |
def test_content(libre):
|
16 |
"""Sample pytest test function with the pytest fixture as an argument."""
|
|
|
|
|
17 |
assert libre.translate(text='good') is not None
|
18 |
|
19 |
|
20 |
def test_inputs():
|
21 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
22 |
LibreTranslator(source="", target="")
|
23 |
|
24 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
25 |
+
LibreTranslator(source="auto", target="")
|
26 |
+
|
27 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
28 |
+
LibreTranslator(source="", target="en")
|
29 |
|
30 |
|
31 |
def test_abbreviations_and_languages_mapping():
|
32 |
for abb, lang in LIBRE_CODES_TO_LANGUAGES.items():
|
33 |
+
l1 = LibreTranslator(abb)
|
34 |
+
l2 = LibreTranslator(lang)
|
35 |
+
assert l1._source == l2._source
|
|
|
36 |
|
37 |
|
38 |
def test_payload(libre):
|
|
|
|
|
|
|
39 |
with pytest.raises(exceptions.NotValidPayload):
|
40 |
libre.translate(123)
|
41 |
|
tests/test_linguee.py
CHANGED
@@ -19,11 +19,14 @@ def test_content(linguee):
|
|
19 |
|
20 |
|
21 |
def test_inputs():
|
22 |
-
with pytest.raises(exceptions.
|
23 |
LingueeTranslator(source="", target="")
|
24 |
|
25 |
-
with pytest.raises(exceptions.
|
26 |
-
LingueeTranslator(source="auto", target="
|
|
|
|
|
|
|
27 |
|
28 |
l1 = LingueeTranslator("en", "fr")
|
29 |
l2 = LingueeTranslator("english", "french")
|
@@ -33,9 +36,6 @@ def test_inputs():
|
|
33 |
|
34 |
def test_payload(linguee):
|
35 |
|
36 |
-
with pytest.raises(exceptions.NotValidPayload):
|
37 |
-
linguee.translate("")
|
38 |
-
|
39 |
with pytest.raises(exceptions.NotValidPayload):
|
40 |
linguee.translate(123)
|
41 |
|
@@ -47,12 +47,3 @@ def test_payload(linguee):
|
|
47 |
|
48 |
with pytest.raises(exceptions.NotValidLength):
|
49 |
linguee.translate("a"*51)
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
def test_translate_words(linguee):
|
54 |
-
words = ['hello', 'world']
|
55 |
-
translated_words = linguee.translate_words(words)
|
56 |
-
|
57 |
-
def test_one_character_words():
|
58 |
-
assert LingueeTranslator(source='es', target='en').translate('y') == 'and'
|
|
|
19 |
|
20 |
|
21 |
def test_inputs():
|
22 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
23 |
LingueeTranslator(source="", target="")
|
24 |
|
25 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
26 |
+
LingueeTranslator(source="auto", target="")
|
27 |
+
|
28 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
29 |
+
LingueeTranslator(source="", target="en")
|
30 |
|
31 |
l1 = LingueeTranslator("en", "fr")
|
32 |
l2 = LingueeTranslator("english", "french")
|
|
|
36 |
|
37 |
def test_payload(linguee):
|
38 |
|
|
|
|
|
|
|
39 |
with pytest.raises(exceptions.NotValidPayload):
|
40 |
linguee.translate(123)
|
41 |
|
|
|
47 |
|
48 |
with pytest.raises(exceptions.NotValidLength):
|
49 |
linguee.translate("a"*51)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tests/test_microsoft_trans.py
CHANGED
@@ -58,5 +58,5 @@ def test_incorrect_target_attributes():
|
|
58 |
def test_abbreviations():
|
59 |
m1 = MicrosoftTranslator(api_key=APIkey, source="en", target="fr")
|
60 |
m2 = MicrosoftTranslator(api_key=APIkey, source="English", target="French")
|
61 |
-
assert ''.join(m1.
|
62 |
-
assert ''.join(m1.
|
|
|
58 |
def test_abbreviations():
|
59 |
m1 = MicrosoftTranslator(api_key=APIkey, source="en", target="fr")
|
60 |
m2 = MicrosoftTranslator(api_key=APIkey, source="English", target="French")
|
61 |
+
assert ''.join(m1._source) == ''.join(m2._source)
|
62 |
+
assert ''.join(m1._target) == ''.join(m2._target)
|
tests/test_mymemory.py
CHANGED
@@ -19,11 +19,15 @@ def test_content(mymemory):
|
|
19 |
|
20 |
|
21 |
def test_inputs():
|
22 |
-
with pytest.raises(exceptions.
|
23 |
MyMemoryTranslator(source="", target="")
|
24 |
|
25 |
-
with pytest.raises(exceptions.
|
26 |
-
MyMemoryTranslator(source="auto", target="
|
|
|
|
|
|
|
|
|
27 |
m1 = MyMemoryTranslator("en", "fr")
|
28 |
m2 = MyMemoryTranslator("english", "french")
|
29 |
assert m1._source == m2._source
|
@@ -48,6 +52,3 @@ def test_payload(mymemory):
|
|
48 |
mymemory.translate(text="a"*501)
|
49 |
|
50 |
|
51 |
-
def test_one_character_words(mymemory):
|
52 |
-
assert mymemory.translate('I')
|
53 |
-
|
|
|
19 |
|
20 |
|
21 |
def test_inputs():
|
22 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
23 |
MyMemoryTranslator(source="", target="")
|
24 |
|
25 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
26 |
+
MyMemoryTranslator(source="auto", target="")
|
27 |
+
|
28 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
29 |
+
MyMemoryTranslator(source="", target="en")
|
30 |
+
|
31 |
m1 = MyMemoryTranslator("en", "fr")
|
32 |
m2 = MyMemoryTranslator("english", "french")
|
33 |
assert m1._source == m2._source
|
|
|
52 |
mymemory.translate(text="a"*501)
|
53 |
|
54 |
|
|
|
|
|
|
tests/test_pons.py
CHANGED
@@ -19,11 +19,15 @@ def test_content(pons):
|
|
19 |
|
20 |
|
21 |
def test_inputs():
|
22 |
-
with pytest.raises(exceptions.
|
23 |
PonsTranslator(source="", target="")
|
24 |
|
25 |
-
with pytest.raises(exceptions.
|
26 |
-
PonsTranslator(source="auto", target="
|
|
|
|
|
|
|
|
|
27 |
l1 = PonsTranslator("en", "fr")
|
28 |
l2 = PonsTranslator("english", "french")
|
29 |
assert l1._source == l2._source
|
@@ -31,10 +35,6 @@ def test_inputs():
|
|
31 |
|
32 |
|
33 |
def test_payload(pons):
|
34 |
-
|
35 |
-
with pytest.raises(exceptions.NotValidPayload):
|
36 |
-
pons.translate("")
|
37 |
-
|
38 |
with pytest.raises(exceptions.NotValidPayload):
|
39 |
pons.translate(123)
|
40 |
|
@@ -47,11 +47,3 @@ def test_payload(pons):
|
|
47 |
with pytest.raises(exceptions.NotValidLength):
|
48 |
pons.translate("a" * 51)
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
def test_translate_words(pons):
|
53 |
-
words = ['hello', 'world']
|
54 |
-
translated_words = pons.translate_words(words)
|
55 |
-
|
56 |
-
def test_one_character_words(pons):
|
57 |
-
assert pons.translate('I')
|
|
|
19 |
|
20 |
|
21 |
def test_inputs():
|
22 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
23 |
PonsTranslator(source="", target="")
|
24 |
|
25 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
26 |
+
PonsTranslator(source="auto", target="")
|
27 |
+
|
28 |
+
with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
|
29 |
+
PonsTranslator(source="", target="en")
|
30 |
+
|
31 |
l1 = PonsTranslator("en", "fr")
|
32 |
l2 = PonsTranslator("english", "french")
|
33 |
assert l1._source == l2._source
|
|
|
35 |
|
36 |
|
37 |
def test_payload(pons):
|
|
|
|
|
|
|
|
|
38 |
with pytest.raises(exceptions.NotValidPayload):
|
39 |
pons.translate(123)
|
40 |
|
|
|
47 |
with pytest.raises(exceptions.NotValidLength):
|
48 |
pons.translate("a" * 51)
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|