Fixed some linting issues
Browse files- tests/test_libre.py +26 -19
tests/test_libre.py
CHANGED
|
@@ -9,25 +9,26 @@ import random
|
|
| 9 |
|
| 10 |
test_text_standard = 'Hello world.'
|
| 11 |
TRANSLATED_RESULTS = {
|
| 12 |
-
'English': 'Hello world.',
|
| 13 |
-
'Arabic': 'مرحبا العالم.',
|
| 14 |
-
'Chinese': '霍洛美世界。',
|
| 15 |
-
'French': 'Bonjour.',
|
| 16 |
'German': 'Hallo Welt.',
|
| 17 |
-
'Hindi': 'नमस्ते दुनिया।',
|
| 18 |
-
'Indonesian': 'Halo dunia.',
|
| 19 |
-
'Irish': 'Dia duit domhan.',
|
| 20 |
-
'Italian': 'Ciao mondo.',
|
| 21 |
'Japanese': 'こんにちは。',
|
| 22 |
-
'Korean': '안녕하세요.',
|
| 23 |
-
'Polish': 'Hello world (ang.).',
|
| 24 |
-
'Portuguese': 'Olá, mundo.',
|
| 25 |
-
'Russian': 'Привет мир.',
|
| 26 |
-
'Spanish': 'Hola mundo.',
|
| 27 |
-
'Turkish': 'Merhaba dünya.',
|
| 28 |
'Vietnamese': 'Xin chào.'
|
| 29 |
}
|
| 30 |
|
|
|
|
| 31 |
@pytest.fixture
|
| 32 |
def libre():
|
| 33 |
return LibreTranslator(source="en", target='fr')
|
|
@@ -39,6 +40,7 @@ def test_content(libre):
|
|
| 39 |
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
| 40 |
assert libre.translate(text='good') is not None
|
| 41 |
|
|
|
|
| 42 |
def test_random_tranlations_cases_multiple_names():
|
| 43 |
random_sample_size = 2
|
| 44 |
d = dict.fromkeys(list(TRANSLATED_RESULTS.keys()))
|
|
@@ -47,6 +49,7 @@ def test_random_tranlations_cases_multiple_names():
|
|
| 47 |
for lang, translation in random_subset_dict.items():
|
| 48 |
assert LibreTranslator(source='en', target=lang).translate(test_text_standard) == translation
|
| 49 |
|
|
|
|
| 50 |
def test_inputs():
|
| 51 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 52 |
LibreTranslator(source="", target="")
|
|
@@ -54,6 +57,7 @@ def test_inputs():
|
|
| 54 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 55 |
LibreTranslator(source="auto", target="nothing")
|
| 56 |
|
|
|
|
| 57 |
def test_abbreviations_and_languages_mapping():
|
| 58 |
for abb, lang in LIBRE_CODES_TO_LANGUAGES.items():
|
| 59 |
if abb != 'en':
|
|
@@ -61,6 +65,7 @@ def test_abbreviations_and_languages_mapping():
|
|
| 61 |
l2 = LibreTranslator(lang)
|
| 62 |
assert l1.source == l2.source
|
| 63 |
|
|
|
|
| 64 |
def test_payload(libre):
|
| 65 |
with pytest.raises(exceptions.NotValidPayload):
|
| 66 |
libre.translate("")
|
|
@@ -78,12 +83,14 @@ def test_payload(libre):
|
|
| 78 |
def test_one_character_words():
|
| 79 |
assert LibreTranslator(source='es', target='en').translate('y') == 'and'
|
| 80 |
|
|
|
|
| 81 |
def test_translate_batch():
|
| 82 |
-
words_to_translate = ['How are you','Good','Thank You']
|
| 83 |
-
translated_words = ['¿Cómo estás?','Bien.','Gracias.']
|
| 84 |
-
assert LibreTranslator(source='en',target='es').translate_batch((words_to_translate)) == translated_words
|
|
|
|
| 85 |
|
| 86 |
def test_translate_file():
|
| 87 |
filePath = 'examples/test.txt'
|
| 88 |
-
translatedText='Un párrafo es una serie de frases relacionadas que desarrollan una idea central, llamada el tema. Trate de pensar en los párrafos en términos de unidad temática: un párrafo es una frase o un grupo de oraciones que apoya una idea central y unificada. Los párrafos añaden una idea a la vez a su argumento más amplio.'
|
| 89 |
-
assert LibreTranslator(source='en',target='es').translate_file(filePath) == translatedText
|
|
|
|
| 9 |
|
| 10 |
test_text_standard = 'Hello world.'
|
| 11 |
TRANSLATED_RESULTS = {
|
| 12 |
+
'English': 'Hello world.',
|
| 13 |
+
'Arabic': 'مرحبا العالم.',
|
| 14 |
+
'Chinese': '霍洛美世界。',
|
| 15 |
+
'French': 'Bonjour.',
|
| 16 |
'German': 'Hallo Welt.',
|
| 17 |
+
'Hindi': 'नमस्ते दुनिया।',
|
| 18 |
+
'Indonesian': 'Halo dunia.',
|
| 19 |
+
'Irish': 'Dia duit domhan.',
|
| 20 |
+
'Italian': 'Ciao mondo.',
|
| 21 |
'Japanese': 'こんにちは。',
|
| 22 |
+
'Korean': '안녕하세요.',
|
| 23 |
+
'Polish': 'Hello world (ang.).',
|
| 24 |
+
'Portuguese': 'Olá, mundo.',
|
| 25 |
+
'Russian': 'Привет мир.',
|
| 26 |
+
'Spanish': 'Hola mundo.',
|
| 27 |
+
'Turkish': 'Merhaba dünya.',
|
| 28 |
'Vietnamese': 'Xin chào.'
|
| 29 |
}
|
| 30 |
|
| 31 |
+
|
| 32 |
@pytest.fixture
|
| 33 |
def libre():
|
| 34 |
return LibreTranslator(source="en", target='fr')
|
|
|
|
| 40 |
# assert 'GitHub' in BeautifulSoup(response.content).title.string
|
| 41 |
assert libre.translate(text='good') is not None
|
| 42 |
|
| 43 |
+
|
| 44 |
def test_random_tranlations_cases_multiple_names():
|
| 45 |
random_sample_size = 2
|
| 46 |
d = dict.fromkeys(list(TRANSLATED_RESULTS.keys()))
|
|
|
|
| 49 |
for lang, translation in random_subset_dict.items():
|
| 50 |
assert LibreTranslator(source='en', target=lang).translate(test_text_standard) == translation
|
| 51 |
|
| 52 |
+
|
| 53 |
def test_inputs():
|
| 54 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 55 |
LibreTranslator(source="", target="")
|
|
|
|
| 57 |
with pytest.raises(exceptions.LanguageNotSupportedException):
|
| 58 |
LibreTranslator(source="auto", target="nothing")
|
| 59 |
|
| 60 |
+
|
| 61 |
def test_abbreviations_and_languages_mapping():
|
| 62 |
for abb, lang in LIBRE_CODES_TO_LANGUAGES.items():
|
| 63 |
if abb != 'en':
|
|
|
|
| 65 |
l2 = LibreTranslator(lang)
|
| 66 |
assert l1.source == l2.source
|
| 67 |
|
| 68 |
+
|
| 69 |
def test_payload(libre):
|
| 70 |
with pytest.raises(exceptions.NotValidPayload):
|
| 71 |
libre.translate("")
|
|
|
|
| 83 |
def test_one_character_words():
|
| 84 |
assert LibreTranslator(source='es', target='en').translate('y') == 'and'
|
| 85 |
|
| 86 |
+
|
| 87 |
def test_translate_batch():
|
| 88 |
+
words_to_translate = ['How are you', 'Good', 'Thank You']
|
| 89 |
+
translated_words = ['¿Cómo estás?', 'Bien.', 'Gracias.']
|
| 90 |
+
assert LibreTranslator(source='en', target='es').translate_batch((words_to_translate)) == translated_words
|
| 91 |
+
|
| 92 |
|
| 93 |
def test_translate_file():
|
| 94 |
filePath = 'examples/test.txt'
|
| 95 |
+
translatedText = 'Un párrafo es una serie de frases relacionadas que desarrollan una idea central, llamada el tema. Trate de pensar en los párrafos en términos de unidad temática: un párrafo es una frase o un grupo de oraciones que apoya una idea central y unificada. Los párrafos añaden una idea a la vez a su argumento más amplio.'
|
| 96 |
+
assert LibreTranslator(source='en', target='es').translate_file(filePath) == translatedText
|