File size: 1,908 Bytes
7275aef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test GPU detection functionality
"""

import pytest
import sys
from pathlib import Path

# Add the parent directory to the path so we can import from cli
sys.path.insert(0, str(Path(__file__).parent.parent))

from cli.main import detect_gpus, choose_training_mode


def test_gpu_detection():
    """Test GPU detection returns valid results"""
    gpu_count, gpus = detect_gpus()
    
    # Should return valid results (even if 0 GPUs)
    assert isinstance(gpu_count, int)
    assert isinstance(gpus, list)
    assert gpu_count >= 0
    assert len(gpus) == gpu_count
    
    # If GPUs are detected, they should have required fields
    for gpu in gpus:
        assert "index" in gpu
        assert "name" in gpu
        assert "memory" in gpu
        assert isinstance(gpu["index"], int)
        assert isinstance(gpu["name"], str)
        assert isinstance(gpu["memory"], str)


def test_training_mode_selection():
    """Test training mode selection logic"""
    # Test with no GPUs
    result = choose_training_mode(0, [])
    assert result is None
    
    # Test with single GPU
    single_gpu = [{"index": 0, "name": "Test GPU", "memory": "8GB"}]
    result = choose_training_mode(1, single_gpu)
    assert result == "single"
    
    # Test with multiple GPUs (would prompt user in real usage)
    multi_gpus = [
        {"index": 0, "name": "GPU 0", "memory": "8GB"},
        {"index": 1, "name": "GPU 1", "memory": "8GB"}
    ]
    # This would normally prompt the user, so we can't test the full flow
    # But we can test that the function can be called
    try:
        result = choose_training_mode(2, multi_gpus)
        # If it returns without error, that's good
        assert result is not None
    except Exception:
        # If it prompts for user input, that's expected in test environment
        pass


if __name__ == "__main__":
    pytest.main([__file__])