nidhal baccouri
commited on
Commit
·
40861f1
1
Parent(s):
3dffcd4
fixed deepl tests
Browse files
deep_translator/deepl.py
CHANGED
|
@@ -12,7 +12,7 @@ class DeepL(object):
|
|
| 12 |
"""
|
| 13 |
_languages = DEEPL_LANGUAGE_TO_CODE
|
| 14 |
|
| 15 |
-
def __init__(self, api_key=None, source="
|
| 16 |
"""
|
| 17 |
@param api_key: your DeepL api key.
|
| 18 |
Get one here: https://www.deepl.com/docs-api/accessing-the-api/
|
|
|
|
| 12 |
"""
|
| 13 |
_languages = DEEPL_LANGUAGE_TO_CODE
|
| 14 |
|
| 15 |
+
def __init__(self, api_key=None, source="en", target="en"):
|
| 16 |
"""
|
| 17 |
@param api_key: your DeepL api key.
|
| 18 |
Get one here: https://www.deepl.com/docs-api/accessing-the-api/
|
deep_translator/tests/test_deepl.py
CHANGED
|
@@ -6,7 +6,7 @@ from deep_translator.exceptions import AuthorizationException
|
|
| 6 |
|
| 7 |
@patch('deep_translator.deepl.requests')
|
| 8 |
def test_simple_translation(mock_requests):
|
| 9 |
-
translator = DeepL(api_key='imagine-this-is-an-valid-api-key')
|
| 10 |
# Set the request response mock.
|
| 11 |
mock_response = Mock()
|
| 12 |
mock_response.status_code = 200
|
|
@@ -16,14 +16,14 @@ def test_simple_translation(mock_requests):
|
|
| 16 |
}]
|
| 17 |
}
|
| 18 |
mock_requests.get.return_value = mock_response
|
| 19 |
-
translation = translator.translate('
|
| 20 |
assert translation == 'hola'
|
| 21 |
|
| 22 |
|
| 23 |
@patch('deep_translator.deepl.requests.get')
|
| 24 |
def test_wrong_api_key(mock_requests):
|
| 25 |
-
translator = DeepL(api_key='this-is-a-wrong-api-key!')
|
| 26 |
# Set the response status_code only.
|
| 27 |
mock_requests.return_value = Mock(status_code=403)
|
| 28 |
with pytest.raises(AuthorizationException):
|
| 29 |
-
translator.translate('
|
|
|
|
| 6 |
|
| 7 |
@patch('deep_translator.deepl.requests')
|
| 8 |
def test_simple_translation(mock_requests):
|
| 9 |
+
translator = DeepL(api_key='imagine-this-is-an-valid-api-key', source='en', target='es')
|
| 10 |
# Set the request response mock.
|
| 11 |
mock_response = Mock()
|
| 12 |
mock_response.status_code = 200
|
|
|
|
| 16 |
}]
|
| 17 |
}
|
| 18 |
mock_requests.get.return_value = mock_response
|
| 19 |
+
translation = translator.translate('hello')
|
| 20 |
assert translation == 'hola'
|
| 21 |
|
| 22 |
|
| 23 |
@patch('deep_translator.deepl.requests.get')
|
| 24 |
def test_wrong_api_key(mock_requests):
|
| 25 |
+
translator = DeepL(api_key='this-is-a-wrong-api-key!', source="en", target="es")
|
| 26 |
# Set the response status_code only.
|
| 27 |
mock_requests.return_value = Mock(status_code=403)
|
| 28 |
with pytest.raises(AuthorizationException):
|
| 29 |
+
translator.translate('Hello')
|