Skip to content

Commit

Permalink
Update test_google_trans.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kuspia authored Aug 25, 2021
1 parent 6438d56 commit f8ccea0
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions tests/test_google_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest
from deep_translator import exceptions, GoogleTranslator
from deep_translator.constants import GOOGLE_CODES_TO_LANGUAGES
from deep_translator.constants import GOOGLE_CODES_TO_LANGUAGES, test_text_standard, TRANSLATED_RESULTS
import random

@pytest.fixture
Expand All @@ -15,20 +15,6 @@ def google_translator():
"""
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_abbreviations_and_languages_mapping():
for abb, lang in GOOGLE_CODES_TO_LANGUAGES.items():
if(abb!= 'en'):
g1 = GoogleTranslator(abb)
g2 = GoogleTranslator(lang)
assert g1._source == g2._source

def case_sensitivity_checks():
test_lang = 'Czech'
test_text = 'Hi, the sky is dark while the moon is white. Hurrah!! Denver is a city name in Colorado.'
Expand Down Expand Up @@ -56,6 +42,29 @@ def multiple_names_lang_checks():
assert GoogleTranslator(source='en', target='Oriya').translate("What's up?") == 'କଣ ଚାଲିଛି?'
assert GoogleTranslator(source='en', target='kurManJi').translate("Nice is dice.") == 'Xweş xweş e.'

def test_random_tranlations_cases_multiple_names():
random_sample_size = 5
d = dict.fromkeys(list(TRANSLATED_RESULTS.keys()))
random_lang_names = random.sample(d.keys(), random_sample_size)
random_subset_dict = {k: TRANSLATED_RESULTS[k] for k in random_lang_names}
for lang, translation in random_subset_dict.items():
assert GoogleTranslator(source='en', target=lang).translate(test_text_standard) == translation

case_sensitivity_checks()
multiple_names_lang_checks()

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_abbreviations_and_languages_mapping():
for abb, lang in GOOGLE_CODES_TO_LANGUAGES.items():
if(abb!= 'en'):
g1 = GoogleTranslator(abb)
g2 = GoogleTranslator(lang)
assert g1._source == g2._source

def test_inputs():
with pytest.raises(exceptions.LanguageNotSupportedException):
Expand All @@ -64,10 +73,6 @@ def test_inputs():
with pytest.raises(exceptions.LanguageNotSupportedException):
GoogleTranslator(source="auto", target="nothing")

case_sensitivity_checks()
multiple_names_lang_checks()


def test_payload(google_translator):

with pytest.raises(exceptions.NotValidPayload):
Expand Down

0 comments on commit f8ccea0

Please # to comment.