fepegar / torchio
1
#!/usr/bin/env python
2

3 3
"""Tests for CLI tool package."""
4

5 3
from click.testing import CliRunner
6 3
from torchio.cli import apply_transform, print_info
7 3
from .utils import TorchioTestCase
8

9

10 3
class TestCLI(TorchioTestCase):
11
    """Tests for CLI tool."""
12 3
    def test_help(self):
13
        """Test the CLI."""
14 3
        runner = CliRunner()
15 3
        help_result = runner.invoke(apply_transform.main, ['--help'])
16 3
        assert help_result.exit_code == 0
17 3
        assert 'Show this message and exit.' in help_result.output
18

19 3
    def test_cli_transform(self):
20 3
        image = str(self.get_image_path('cli'))
21 3
        runner = CliRunner()
22 3
        args = [
23
            image,
24
            'RandomFlip',
25
            '--seed', '0',
26
            '--kwargs', 'axes=(0,1,2)',
27
            image,
28
        ]
29 3
        result = runner.invoke(apply_transform.main, args)
30 3
        assert result.exit_code == 0
31 3
        assert result.output == ''
32

33 3
    def test_bad_transform(self):
34 3
        ValueError
35 3
        image = str(self.get_image_path('cli'))
36 3
        runner = CliRunner()
37 3
        args = [image, 'RandomRandom', image]
38 3
        result = runner.invoke(apply_transform.main, args)
39 3
        assert result.exit_code == 1
40

41 3
    def test_cli_hd(self):
42 3
        image = str(self.get_image_path('cli'))
43 3
        runner = CliRunner()
44 3
        args = [image]
45 3
        result = runner.invoke(print_info.main, args)
46 3
        assert result.exit_code == 0
47 3
        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

Read our documentation on viewing source code .

Loading