File size: 2,035 Bytes
24836e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""モデルファイルパスのテスト(TDD: RED → GREEN)"""

import pytest
from pathlib import Path


class TestModelPath:
    """モデルファイルの検索ロジックのテスト"""

    def test_get_model_path_finds_model_file(self):
        """モデルファイルが見つかること"""
        from rock_paper_scissors.detection.hand_detector import _get_model_path

        # モデルファイルが存在するパスを返す
        model_path = _get_model_path()

        assert model_path.exists(), f"Model file not found at {model_path}"
        assert model_path.name == "hand_landmarker.task"

    def test_get_model_path_checks_multiple_locations(self):
        """複数の場所を検索すること"""
        from rock_paper_scissors.detection.hand_detector import _get_model_path

        # 正常にパスが返されることを確認
        model_path = _get_model_path()
        assert isinstance(model_path, Path)


class TestHandDetectorInitialization:
    """HandDetectorの初期化テスト"""

    def test_hand_detector_can_be_instantiated(self):
        """HandDetectorがインスタンス化できること"""
        pytest.importorskip("mediapipe")

        from rock_paper_scissors.detection.hand_detector import HandDetector

        # インスタンス化が成功すること
        detector = HandDetector()
        assert detector is not None

        # クリーンアップ
        detector.close()

    def test_hand_detector_raises_if_mediapipe_not_available(self):
        """MediaPipeがない場合はエラー"""
        from rock_paper_scissors.detection import hand_detector

        # MediaPipeがインストールされている場合はスキップ
        if hand_detector.MEDIAPIPE_AVAILABLE:
            pytest.skip("MediaPipe is available, cannot test unavailable case")

        from rock_paper_scissors.detection.hand_detector import HandDetector

        with pytest.raises(RuntimeError, match="MediaPipe is not installed"):
            HandDetector()