Spaces:
Sleeping
Sleeping
| """ | |
| 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 | |