-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest_cli.py
37 lines (29 loc) · 1.19 KB
/
test_cli.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
import subprocess
from typing import List, Union
from mtdata.index import INDEX as index
from pathlib import Path
from tempfile import TemporaryDirectory
def shrun(cmd: Union[str, List[str]], capture_output=False):
p = subprocess.run(cmd, shell=isinstance(cmd, str),
capture_output=True)
if capture_output:
return p.returncode, p.stdout
return p.returncode
def test_cli_help():
assert shrun('python -m mtdata --help') == 0
def test_cli_list():
code, out = shrun('python -m mtdata list --id', capture_output=True)
assert code == 0
assert len(out.splitlines()) >= len(index.entries)
def test_cli_get():
with TemporaryDirectory() as out_dir:
did = 'OPUS-gnome-v1-eng-kan'
assert shrun(f'python -m mtdata get -l eng-kan -tr {did} -o {out_dir}') == 0
assert (Path(out_dir) / 'mtdata.signature.txt').exists()
def test_cache():
code = shrun('python -m mtdata cache -ri tg01_2to1_test -j3', capture_output=False)
assert code == 0
def test_get_recipe():
with TemporaryDirectory() as out_dir:
code = shrun(f'python -m mtdata get-recipe -ri tg01_2to1_test -o {out_dir}', capture_output=False)
assert code == 0