Passed
Push — master ( b383b7...b7424a )
by Fernando
01:21
created

tests.test_cli.TestCLI.test_cli()   A

Complexity

Conditions 1

Size

Total Lines 7
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python
2
3
"""Tests for CLI tool package."""
4
5
from click.testing import CliRunner
6
from torchio.cli import apply_transform, print_info
7
from .utils import TorchioTestCase
8
9
10
class TestCLI(TorchioTestCase):
11
    """Tests for CLI tool."""
12
    def test_help(self):
13
        """Test the CLI."""
14
        runner = CliRunner()
15
        help_result = runner.invoke(apply_transform.main, ['--help'])
16
        assert help_result.exit_code == 0
17
        assert 'Show this message and exit.' in help_result.output
18
19
    def test_cli_transform(self):
20
        image = str(self.get_image_path('cli'))
21
        runner = CliRunner()
22
        args = [
23
            image,
24
            'RandomFlip',
25
            '--seed', '0',
26
            '--kwargs', 'axes=(0,1,2)',
27
            image,
28
        ]
29
        result = runner.invoke(apply_transform.main, args)
30
        assert result.exit_code == 0
31
        assert result.output == ''
32
33
    def test_bad_transform(self):
34
        ValueError
35
        image = str(self.get_image_path('cli'))
36
        runner = CliRunner()
37
        args = [image, 'RandomRandom', image]
38
        result = runner.invoke(apply_transform.main, args)
39
        assert result.exit_code == 1
40
41
    def test_cli_hd(self):
42
        image = str(self.get_image_path('cli'))
43
        runner = CliRunner()
44
        args = [image]
45
        result = runner.invoke(print_info.main, args)
46
        assert result.exit_code == 0
47
        assert result.output == 'ScalarImage(shape: (1, 10, 20, 30); spacing: (1.00, 1.00, 1.00); orientation: RAS+; memory: 46.9 KiB; dtype: torch.DoubleTensor)\n'  # noqa: E501
48