kuspia
commited on
Update test_google_trans.py
Browse files- tests/test_google_trans.py +35 -8
tests/test_google_trans.py
CHANGED
@@ -4,7 +4,8 @@
|
|
4 |
|
5 |
import pytest
|
6 |
from deep_translator import exceptions, GoogleTranslator
|
7 |
-
|
|
|
8 |
|
9 |
@pytest.fixture
|
10 |
def google_translator():
|
@@ -14,7 +15,6 @@ def google_translator():
|
|
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 |
# from bs4 import BeautifulSoup
|
@@ -22,6 +22,13 @@ def test_content(google_translator):
|
|
22 |
assert google_translator.translate(text='좋은') == "good"
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
def test_inputs():
|
26 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
27 |
GoogleTranslator(source="", target="")
|
@@ -29,11 +36,32 @@ def test_inputs():
|
|
29 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
30 |
GoogleTranslator(source="auto", target="nothing")
|
31 |
|
32 |
-
#
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
|
39 |
def test_payload(google_translator):
|
@@ -59,6 +87,5 @@ def test_payload(google_translator):
|
|
59 |
#for _ in range(1):
|
60 |
#assert google_translator.translate(text='좋은') == "good"
|
61 |
|
62 |
-
|
63 |
def test_one_character_words():
|
64 |
assert GoogleTranslator(source='es', target='en').translate('o') == 'or'
|
|
|
4 |
|
5 |
import pytest
|
6 |
from deep_translator import exceptions, GoogleTranslator
|
7 |
+
from deep_translator.constants import GOOGLE_CODES_TO_LANGUAGES
|
8 |
+
import random
|
9 |
|
10 |
@pytest.fixture
|
11 |
def google_translator():
|
|
|
15 |
"""
|
16 |
return GoogleTranslator(target='en')
|
17 |
|
|
|
18 |
def test_content(google_translator):
|
19 |
"""Sample pytest test function with the pytest fixture as an argument."""
|
20 |
# from bs4 import BeautifulSoup
|
|
|
22 |
assert google_translator.translate(text='좋은') == "good"
|
23 |
|
24 |
|
25 |
+
def test_abbreviations_and_languages_mapping():
|
26 |
+
for abb, lang in GOOGLE_CODES_TO_LANGUAGES.items():
|
27 |
+
if(abb!= 'en'):
|
28 |
+
g1 = GoogleTranslator(abb)
|
29 |
+
g2 = GoogleTranslator(lang)
|
30 |
+
assert g1._source == g2._source
|
31 |
+
|
32 |
def test_inputs():
|
33 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
34 |
GoogleTranslator(source="", target="")
|
|
|
36 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
37 |
GoogleTranslator(source="auto", target="nothing")
|
38 |
|
39 |
+
# Case Senstivity checks
|
40 |
+
test_lang = 'Czech'
|
41 |
+
test_text = 'Hi, the sky is dark while the moon is white. Hurrah!! Denver is a city name in Colorado.'
|
42 |
+
translated_text = 'Ahoj, obloha je tmavá, zatímco měsíc je bílý. Hurá!! Denver je název města v Coloradu.'
|
43 |
+
test_cases = []
|
44 |
+
n = len(test_lang)
|
45 |
+
mx = 1 << n
|
46 |
+
test = test_lang.lower()
|
47 |
+
for i in range(mx):
|
48 |
+
combination = [k for k in test_lang]
|
49 |
+
for j in range(n):
|
50 |
+
if (((i >> j) & 1) == 1):
|
51 |
+
combination[j] = test_lang[j].upper()
|
52 |
+
temp = ""
|
53 |
+
for i in combination:
|
54 |
+
temp += i
|
55 |
+
test_cases.append(temp)
|
56 |
+
random_cases = 5
|
57 |
+
random_test_cases = random.sample(test_cases, random_cases) # randomly choosing any five cases since list is in order of 2^n
|
58 |
+
for case in random_test_cases:
|
59 |
+
assert GoogleTranslator(source='en', target=case).translate(test_text) == translated_text
|
60 |
+
|
61 |
+
# Languages with multiple names checks
|
62 |
+
assert GoogleTranslator(source='en', target='burMeSe').translate("Hello") == 'မင်္ဂလာပါ'
|
63 |
+
assert GoogleTranslator(source='en', target='Oriya').translate("What's up?") == 'କଣ ଚାଲିଛି?'
|
64 |
+
assert GoogleTranslator(source='en', target='kurManJi').translate("Nice is dice.") == 'Xweş xweş e.'
|
65 |
|
66 |
|
67 |
def test_payload(google_translator):
|
|
|
87 |
#for _ in range(1):
|
88 |
#assert google_translator.translate(text='좋은') == "good"
|
89 |
|
|
|
90 |
def test_one_character_words():
|
91 |
assert GoogleTranslator(source='es', target='en').translate('o') == 'or'
|