kuspia commited on
Commit
f8ccea0
·
unverified ·
1 Parent(s): 6438d56

Update test_google_trans.py

Browse files
Files changed (1) hide show
  1. tests/test_google_trans.py +24 -19
tests/test_google_trans.py CHANGED
@@ -4,7 +4,7 @@
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
@@ -15,20 +15,6 @@ 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
21
- # assert 'GitHub' in BeautifulSoup(response.content).title.string
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 case_sensitivity_checks():
33
  test_lang = 'Czech'
34
  test_text = 'Hi, the sky is dark while the moon is white. Hurrah!! Denver is a city name in Colorado.'
@@ -56,6 +42,29 @@ def multiple_names_lang_checks():
56
  assert GoogleTranslator(source='en', target='Oriya').translate("What's up?") == 'କଣ ଚାଲିଛି?'
57
  assert GoogleTranslator(source='en', target='kurManJi').translate("Nice is dice.") == 'Xweş xweş e.'
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  def test_inputs():
61
  with pytest.raises(exceptions.LanguageNotSupportedException):
@@ -64,10 +73,6 @@ def test_inputs():
64
  with pytest.raises(exceptions.LanguageNotSupportedException):
65
  GoogleTranslator(source="auto", target="nothing")
66
 
67
- case_sensitivity_checks()
68
- multiple_names_lang_checks()
69
-
70
-
71
  def test_payload(google_translator):
72
 
73
  with pytest.raises(exceptions.NotValidPayload):
 
4
 
5
  import pytest
6
  from deep_translator import exceptions, GoogleTranslator
7
+ from deep_translator.constants import GOOGLE_CODES_TO_LANGUAGES, test_text_standard, TRANSLATED_RESULTS
8
  import random
9
 
10
  @pytest.fixture
 
15
  """
16
  return GoogleTranslator(target='en')
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  def case_sensitivity_checks():
19
  test_lang = 'Czech'
20
  test_text = 'Hi, the sky is dark while the moon is white. Hurrah!! Denver is a city name in Colorado.'
 
42
  assert GoogleTranslator(source='en', target='Oriya').translate("What's up?") == 'କଣ ଚାଲିଛି?'
43
  assert GoogleTranslator(source='en', target='kurManJi').translate("Nice is dice.") == 'Xweş xweş e.'
44
 
45
+ def test_random_tranlations_cases_multiple_names():
46
+ random_sample_size = 5
47
+ d = dict.fromkeys(list(TRANSLATED_RESULTS.keys()))
48
+ random_lang_names = random.sample(d.keys(), random_sample_size)
49
+ random_subset_dict = {k: TRANSLATED_RESULTS[k] for k in random_lang_names}
50
+ for lang, translation in random_subset_dict.items():
51
+ assert GoogleTranslator(source='en', target=lang).translate(test_text_standard) == translation
52
+
53
+ case_sensitivity_checks()
54
+ multiple_names_lang_checks()
55
+
56
+ def test_content(google_translator):
57
+ """Sample pytest test function with the pytest fixture as an argument."""
58
+ # from bs4 import BeautifulSoup
59
+ # assert 'GitHub' in BeautifulSoup(response.content).title.string
60
+ assert google_translator.translate(text='좋은') == "good"
61
+
62
+ def test_abbreviations_and_languages_mapping():
63
+ for abb, lang in GOOGLE_CODES_TO_LANGUAGES.items():
64
+ if(abb!= 'en'):
65
+ g1 = GoogleTranslator(abb)
66
+ g2 = GoogleTranslator(lang)
67
+ assert g1._source == g2._source
68
 
69
  def test_inputs():
70
  with pytest.raises(exceptions.LanguageNotSupportedException):
 
73
  with pytest.raises(exceptions.LanguageNotSupportedException):
74
  GoogleTranslator(source="auto", target="nothing")
75
 
 
 
 
 
76
  def test_payload(google_translator):
77
 
78
  with pytest.raises(exceptions.NotValidPayload):