Spaces:
Sleeping
Sleeping
File size: 9,511 Bytes
c87f72b | 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | """
Comprehensive tests for app.py (Streamlit TIA-ARCHITECT-CORE)
Tests cover:
- Configuration and constants
- Environment variable checking
- Path management
- Data directory structure
"""
import pytest
import os
from pathlib import Path
from unittest.mock import Mock, patch, MagicMock
import sys
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
class TestAppConfiguration:
"""Test app.py configuration"""
def test_identity_structure(self):
"""Test IDENTITY constant has correct structure"""
# We can't easily import streamlit code, but we can test the structure
# by reading the file
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'IDENTITY' in content
assert '"name": "T.I.A."' in content
assert '"version"' in content
assert '"github"' in content
assert '"huggingface"' in content
def test_page_config_present(self):
"""Test that page config is set"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'st.set_page_config' in content
assert 'page_title' in content
assert 'TIA-ARCHITECT-CORE' in content
def test_required_imports(self):
"""Test that required imports are present"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
required_imports = [
'import streamlit as st',
'from pathlib import Path',
'from datetime import datetime',
'import json',
'import sys',
'import os'
]
for imp in required_imports:
assert imp in content
def test_tabs_defined(self):
"""Test that all tabs are defined"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
expected_tabs = [
'🏠 Dashboard',
'🤖 Models',
'⚙️ Workers',
'📚 Knowledge Base',
'🔧 Tools'
]
for tab in expected_tabs:
assert tab in content
class TestEnvironmentVariables:
"""Test environment variable handling"""
def test_env_vars_checked(self):
"""Test that environment variables are checked"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
expected_env_vars = [
'HF_TOKEN',
'GITHUB_TOKEN',
'GOOGLE_API_KEY'
]
for var in expected_env_vars:
assert var in content
def test_env_status_dict(self):
"""Test that env_status dict is created"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'env_status' in content
assert 'os.getenv' in content
class TestDataDirectories:
"""Test data directory structure"""
def test_data_paths_defined(self):
"""Test that data paths are defined"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'data_dir' in content or 'Path("data")' in content
assert 'models_dir' in content or 'models' in content
assert 'workers_dir' in content or 'workers' in content
def test_manifest_files_referenced(self):
"""Test that manifest files are referenced"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'models_manifest' in content or 'models_manifest.json' in content
assert 'workers_manifest' in content or 'workers_manifest.json' in content
class TestDistrictTopology:
"""Test district topology configuration"""
def test_districts_defined(self):
"""Test that districts are defined"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
expected_districts = ['D01', 'D02', 'D03', 'D04', 'D05', 'D06']
for district in expected_districts:
assert district in content
def test_district_descriptions(self):
"""Test that district descriptions exist"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
expected_descriptions = [
'Core Infrastructure',
'Data Processing',
'Security',
'ML Models',
'API'
]
for desc in expected_descriptions:
assert desc in content
class TestUIComponents:
"""Test UI components and structure"""
def test_sidebar_elements(self):
"""Test that sidebar elements are defined"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'st.sidebar' in content or 'with st.sidebar' in content
assert 'System Status' in content
def test_metrics_defined(self):
"""Test that metrics are displayed"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'st.metric' in content
def test_tabs_structure(self):
"""Test that tabs are properly structured"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'st.tabs' in content
assert 'with tab1' in content or 'with tab' in content
class TestModelsRegistry:
"""Test models registry integration"""
def test_models_manifest_loading(self):
"""Test that models manifest loading is implemented"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'models_manifest_path' in content or 'models_manifest.json' in content
assert 'json.load' in content
def test_model_categories_display(self):
"""Test that model categories are displayed"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'categories' in content
assert 'st.expander' in content
class TestWorkersConstellation:
"""Test workers constellation integration"""
def test_workers_manifest_loading(self):
"""Test that workers manifest loading is implemented"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'workers_manifest' in content or 'workers_manifest.json' in content
def test_worker_types_referenced(self):
"""Test that worker types are referenced"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'Apps Script' in content or 'Worker Watchdog' in content
class TestRAGSystem:
"""Test RAG system integration"""
def test_rag_references(self):
"""Test that RAG system is referenced"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'RAG' in content or 'Knowledge Base' in content
def test_oracle_engine(self):
"""Test that Oracle engine is referenced"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'Oracle' in content
class TestToolsAndUtilities:
"""Test tools and utilities section"""
def test_system_information(self):
"""Test that system information is displayed"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'sys.version' in content or 'Python Version' in content
assert 'os.getcwd' in content or 'Working Directory' in content
def test_quick_actions(self):
"""Test that quick actions are defined"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'st.button' in content
def test_config_export(self):
"""Test that config export is implemented"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'download_button' in content or 'Export Config' in content
class TestIntegration:
"""Integration tests for app.py"""
def test_app_structure_complete(self):
"""Test that app has complete structure"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
# Check all major sections exist
sections = [
'PAGE CONFIGURATION',
'IDENTITY',
'SIDEBAR',
'MAIN DASHBOARD',
'TAB 1',
'TAB 2',
'TAB 3',
'TAB 4',
'TAB 5',
'FOOTER'
]
for section in sections:
assert section in content
def test_no_duplicate_page_config(self):
"""Test that st.set_page_config is called only once"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
# Should only appear once
count = content.count('st.set_page_config')
assert count == 1
def test_double_n_rift_referenced(self):
"""Test that Double-N Rift is referenced"""
app_path = Path(__file__).parent.parent / "app.py"
content = app_path.read_text()
assert 'DJ-Goana-Coding' in content # Single N
assert 'DJ-Goanna-Coding' in content # Double N
|