forked from templateflow/python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
69 lines (41 loc) · 1.82 KB
/
test_cli.py
File metadata and controls
69 lines (41 loc) · 1.82 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from pathlib import Path
import click.testing
import pytest
from .. import cli
@pytest.fixture
def runner():
return click.testing.CliRunner()
def test_ls_one(runner):
result = runner.invoke(cli.main, ['ls', 'MNI152Lin', '--res', '1', '-s', 'T1w'])
# One result
lines = result.stdout.strip().splitlines()
assert len(lines) == 1
assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0]
path = Path(lines[0])
assert path.exists()
def test_ls_multi(runner):
result = runner.invoke(cli.main, ['ls', 'MNI152Lin', '--res', '1', '-s', 'T1w', '-s', 'T2w'])
# Two results
lines = result.stdout.strip().splitlines()
assert len(lines) == 2
assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0]
assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T2w.nii.gz' in lines[1]
paths = [Path(line) for line in lines]
assert all(path.exists() for path in paths)
def test_get_one(runner):
result = runner.invoke(cli.main, ['get', 'MNI152Lin', '--res', '1', '-s', 'T1w'])
# One result, possible download status before
lines = result.stdout.strip().splitlines()[-2:]
assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0]
path = Path(lines[0])
stat_res = path.stat()
assert stat_res.st_size == 10669511
def test_get_multi(runner):
result = runner.invoke(cli.main, ['get', 'MNI152Lin', '--res', '1', '-s', 'T1w', '-s', 'T2w'])
# Two result, possible download status before
lines = result.stdout.strip().splitlines()[-3:]
assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0]
assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T2w.nii.gz' in lines[1]
paths = [Path(line) for line in lines]
stats = [path.stat() for path in paths]
assert [stat_res.st_size for stat_res in stats] == [10669511, 10096230]