File size: 2,459 Bytes
3f8bf9c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
"""Tests for CLI."""

from __future__ import annotations

from unittest.mock import MagicMock, patch

from stroke_deepisles_demo.cli import main
from stroke_deepisles_demo.pipeline import PipelineResult


class TestCli:
    """Tests for CLI entry point."""

    def test_list_command(self) -> None:
        """List command prints cases."""
        with (
            patch("stroke_deepisles_demo.cli.list_case_ids", return_value=["sub-001"]),
            patch("builtins.print") as mock_print,
        ):
            exit_code = main(["list"])
            assert exit_code == 0
            mock_print.assert_called()

    def test_run_command_by_index(self) -> None:
        """Run command with index calls pipeline."""
        result = PipelineResult(
            case_id="sub-001",
            input_files=MagicMock(),
            staged_dir=MagicMock(),
            prediction_mask=MagicMock(),
            ground_truth=None,
            dice_score=None,
            elapsed_seconds=10.0,
        )

        with patch(
            "stroke_deepisles_demo.cli.run_pipeline_on_case", return_value=result
        ) as mock_run:
            exit_code = main(["run", "--index", "0"])
            assert exit_code == 0

            mock_run.assert_called_once()
            kwargs = mock_run.call_args.kwargs
            assert kwargs["case_id"] == 0
            assert kwargs["fast"] is True  # Default
            assert kwargs["gpu"] is True  # Default

    def test_run_command_by_id_no_gpu(self) -> None:
        """Run command with ID and no-gpu flag."""
        result = PipelineResult(
            case_id="sub-001",
            input_files=MagicMock(),
            staged_dir=MagicMock(),
            prediction_mask=MagicMock(),
            ground_truth=None,
            dice_score=None,
            elapsed_seconds=10.0,
        )

        with patch(
            "stroke_deepisles_demo.cli.run_pipeline_on_case", return_value=result
        ) as mock_run:
            exit_code = main(["run", "--case", "sub-001", "--no-gpu"])
            assert exit_code == 0

            kwargs = mock_run.call_args.kwargs
            assert kwargs["case_id"] == "sub-001"
            assert kwargs["gpu"] is False

    def test_run_command_fails_without_arg(self) -> None:
        """Run command fails if no case specified."""
        with patch("builtins.print"):  # Suppress error output
            exit_code = main(["run"])
            assert exit_code == 1