Chris Trenthem
commited on
Commit
·
9fa6116
1
Parent(s):
ee8b0c3
fixed test_cli.py
Browse files- deep_translator/main.py +1 -1
- deep_translator/tests/test_cli.py +21 -14
deep_translator/main.py
CHANGED
@@ -22,7 +22,7 @@ def cli():
|
|
22 |
@click.option("--target", "-tgt", required=True, type=str, help="target language to translate to")
|
23 |
@click.option("--text", "-txt", type=str,required = True,prompt="Enter the text you want to translate",help="text you want to translate")
|
24 |
@click.option("--api-key",type=str,help="required for DeepL, QCRI, Yandex, Microsoft and Papago translators")
|
25 |
-
def translate(translator, source, target, text, api_key
|
26 |
"""
|
27 |
Use TRANSLATOR to translate source material into another language.
|
28 |
\f
|
|
|
22 |
@click.option("--target", "-tgt", required=True, type=str, help="target language to translate to")
|
23 |
@click.option("--text", "-txt", type=str,required = True,prompt="Enter the text you want to translate",help="text you want to translate")
|
24 |
@click.option("--api-key",type=str,help="required for DeepL, QCRI, Yandex, Microsoft and Papago translators")
|
25 |
+
def translate(translator, source, target, text, api_key):
|
26 |
"""
|
27 |
Use TRANSLATOR to translate source material into another language.
|
28 |
\f
|
deep_translator/tests/test_cli.py
CHANGED
@@ -3,21 +3,28 @@
|
|
3 |
"""Tests for the CLI interface."""
|
4 |
|
5 |
from click.testing import CliRunner
|
6 |
-
from deep_translator import
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
def
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
3 |
"""Tests for the CLI interface."""
|
4 |
|
5 |
from click.testing import CliRunner
|
6 |
+
from deep_translator.main import cli
|
7 |
|
8 |
+
class TestClass:
|
9 |
+
def test_translate(self):
|
10 |
+
runner = CliRunner()
|
11 |
+
result = runner.invoke(cli, ['translate', 'google', '-src=auto', '-tgt=en', '-txt=좋은'])
|
12 |
+
assert 'good' in result.output
|
13 |
+
assert result.exit_code == 0
|
14 |
|
15 |
+
def test_api_key_error(self):
|
16 |
+
runner = CliRunner()
|
17 |
+
result = runner.invoke(cli, ['translate', 'microsoft','-src=auto','-tgt=en','-txt=\'Zwei minimale Dellchen auf der Rückseite.\''])
|
18 |
+
assert "This translator requires an api key provided through --api-key" in result.output
|
19 |
+
assert result.exit_code == 1
|
20 |
|
21 |
+
def test_language_languages(self):
|
22 |
+
runner = CliRunner()
|
23 |
+
result = runner.invoke(cli, ['languages', 'google'])
|
24 |
+
assert result.exit_code == 0
|
25 |
|
26 |
+
def test_invalid_language_languages(self):
|
27 |
+
runner = CliRunner()
|
28 |
+
result = runner.invoke(cli, ['languages', 'notValidTranslator'])
|
29 |
+
assert 'The given translator is not supported.' in str(result.exception)
|
30 |
+
assert result.exit_code == 1
|