|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +import click.testing |
| 4 | +import pytest |
| 5 | + |
| 6 | +from .. import cli |
| 7 | + |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def runner(): |
| 11 | + return click.testing.CliRunner() |
| 12 | + |
| 13 | + |
| 14 | +def test_ls_one(runner): |
| 15 | + result = runner.invoke(cli.main, ['ls', 'MNI152Lin', '--res', '1', '-s', 'T1w']) |
| 16 | + |
| 17 | + # One result |
| 18 | + lines = result.stdout.strip().splitlines() |
| 19 | + assert len(lines) == 1 |
| 20 | + |
| 21 | + assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] |
| 22 | + |
| 23 | + path = Path(lines[0]) |
| 24 | + |
| 25 | + assert path.exists() |
| 26 | + |
| 27 | + |
| 28 | +def test_ls_multi(runner): |
| 29 | + result = runner.invoke(cli.main, ['ls', 'MNI152Lin', '--res', '1', '-s', 'T1w', '-s', 'T2w']) |
| 30 | + |
| 31 | + # Two results |
| 32 | + lines = result.stdout.strip().splitlines() |
| 33 | + assert len(lines) == 2 |
| 34 | + |
| 35 | + assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] |
| 36 | + assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T2w.nii.gz' in lines[1] |
| 37 | + |
| 38 | + paths = [Path(line) for line in lines] |
| 39 | + |
| 40 | + assert all(path.exists() for path in paths) |
| 41 | + |
| 42 | + |
| 43 | +def test_get_one(runner): |
| 44 | + result = runner.invoke(cli.main, ['get', 'MNI152Lin', '--res', '1', '-s', 'T1w']) |
| 45 | + |
| 46 | + # One result, possible download status before |
| 47 | + lines = result.stdout.strip().splitlines()[-2:] |
| 48 | + |
| 49 | + assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] |
| 50 | + |
| 51 | + path = Path(lines[0]) |
| 52 | + |
| 53 | + stat_res = path.stat() |
| 54 | + assert stat_res.st_size == 10669511 |
| 55 | + |
| 56 | + |
| 57 | +def test_get_multi(runner): |
| 58 | + result = runner.invoke(cli.main, ['get', 'MNI152Lin', '--res', '1', '-s', 'T1w', '-s', 'T2w']) |
| 59 | + |
| 60 | + # Two result, possible download status before |
| 61 | + lines = result.stdout.strip().splitlines()[-3:] |
| 62 | + |
| 63 | + assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T1w.nii.gz' in lines[0] |
| 64 | + assert 'tpl-MNI152Lin/tpl-MNI152Lin_res-01_T2w.nii.gz' in lines[1] |
| 65 | + |
| 66 | + paths = [Path(line) for line in lines] |
| 67 | + |
| 68 | + stats = [path.stat() for path in paths] |
| 69 | + assert [stat_res.st_size for stat_res in stats] == [10669511, 10096230] |
0 commit comments