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