File size: 4,884 Bytes
e526e6a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
Basic tests for SPIRAL Interactive Reasoning Game Simulator.

This module contains fundamental tests to verify the core functionality
of the SPIRAL system components.
"""

import pytest
import os
import sys
import yaml

# Add the src directory to the path for imports
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'src'))
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'app'))

from app import SpiralApp

class TestSpiralApp:
    """Test cases for the main SPIRAL application."""
    
    def test_app_initialization(self):
        """Test that the app initializes correctly."""
        app = SpiralApp()
        assert app is not None
        assert hasattr(app, 'config')
        assert hasattr(app, 'play_game')
        assert hasattr(app, 'test_reasoning')
    
    def test_config_loading(self):
        """Test configuration loading."""
        app = SpiralApp()
        assert 'interface' in app.config
        assert 'games' in app.config
        assert app.config['interface']['title'] is not None
    
    def test_play_game_basic(self):
        """Test basic game play functionality."""
        app = SpiralApp()
        
        # Test with valid input
        state, response, trace = app.play_game("kuhn_poker", "bet", "")
        assert state is not None
        assert response is not None
        assert trace is not None
        assert "bet" in state
        
        # Test with empty input
        state, response, trace = app.play_game("kuhn_poker", "", "")
        assert "Please enter a move!" in response
    
    def test_reasoning_basic(self):
        """Test basic reasoning functionality."""
        app = SpiralApp()
        
        # Test with valid input
        response, trace = app.test_reasoning("What is 2+2?", "math")
        assert response is not None
        assert trace is not None
        assert "2+2" in response
        
        # Test with empty input
        response, trace = app.test_reasoning("", "math")
        assert "Please enter a reasoning prompt!" in response
    
    def test_interface_creation(self):
        """Test that the Gradio interface can be created."""
        app = SpiralApp()
        demo = app.create_interface()
        assert demo is not None

class TestConfiguration:
    """Test cases for configuration management."""
    
    def test_config_file_structure(self):
        """Test that config.yaml has the expected structure."""
        config_path = os.path.join(os.path.dirname(__file__), '..', 'config.yaml')
        
        if os.path.exists(config_path):
            with open(config_path, 'r') as f:
                config = yaml.safe_load(f)
            
            # Check required sections
            assert 'model' in config
            assert 'games' in config
            assert 'training' in config
            assert 'reasoning' in config
            assert 'interface' in config
            
            # Check model configuration
            assert 'name' in config['model']
            assert 'max_length' in config['model']
            
            # Check games configuration
            assert 'kuhn_poker' in config['games']
            assert 'tictactoe' in config['games']

class TestProjectStructure:
    """Test cases for project structure and imports."""
    
    def test_src_directory_structure(self):
        """Test that the src directory has the expected structure."""
        src_path = os.path.join(os.path.dirname(__file__), '..', 'src')
        
        # Check that required directories exist
        assert os.path.exists(os.path.join(src_path, 'games'))
        assert os.path.exists(os.path.join(src_path, 'models'))
        assert os.path.exists(os.path.join(src_path, 'training'))
        assert os.path.exists(os.path.join(src_path, 'reasoning'))
        
        # Check that __init__.py files exist
        assert os.path.exists(os.path.join(src_path, '__init__.py'))
        assert os.path.exists(os.path.join(src_path, 'games', '__init__.py'))
        assert os.path.exists(os.path.join(src_path, 'models', '__init__.py'))
        assert os.path.exists(os.path.join(src_path, 'training', '__init__.py'))
        assert os.path.exists(os.path.join(src_path, 'reasoning', '__init__.py'))
    
    def test_required_files_exist(self):
        """Test that required project files exist."""
        project_root = os.path.join(os.path.dirname(__file__), '..')
        
        # Check essential files
        assert os.path.exists(os.path.join(project_root, 'requirements.txt'))
        assert os.path.exists(os.path.join(project_root, 'README.md'))
        assert os.path.exists(os.path.join(project_root, 'config.yaml'))
        assert os.path.exists(os.path.join(project_root, '.gitignore'))
        assert os.path.exists(os.path.join(project_root, 'app', 'app.py'))

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