forked from fulfilio/Microsoft-Translator-Python-API
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.py
54 lines (39 loc) · 1.48 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
"""
test
Test the translator
"""
import os
import unittest
from microsofttranslator import Translator, TranslateApiException
client_id = os.environ['CLIENT_ID']
client_secret = os.environ['CLIENT_SECRET']
default_languages = [u'en', u'fr', u'de']
class TestTranslator(unittest.TestCase):
def test_translate(self):
client = Translator(client_id, client_secret, debug=True)
self.assertEqual(
client.translate("hello", "pt"), u'Ol\xe1'
)
def test_translate_array(self):
client = Translator(client_id, client_secret, debug=True)
self.assertEqual(client.translate("hello", "pt"), u'Ol\xe1')
def test_invalid_client_id(self):
client = Translator("foo", "bar")
with self.assertRaises(TranslateApiException):
client.translate("hello", "pt")
def test_get_languages(self):
client = Translator(client_id, client_secret, debug=True)
languages = client.get_languages()
self.assertEqual(type(languages), list)
self.assertTrue(set(default_languages).issubset(set(languages)))
def test_detect_language(self):
client = Translator(client_id, client_secret, debug=True)
self.assertEqual(client.detect_language('hello'), u'en')
def test_all():
loader = unittest.TestLoader()
suite = unittest.TestSuite()
suite.addTests(loader.loadTestsFromTestCase(TestTranslator))
return suite
if __name__ == '__main__':
unittest.main()