whackthejacker/DataHubHub
1
1"""2Simple test file for the ML Dataset & Code Generation Manager application.3This script checks basic aspects of the application structure and setup.4"""5 6import os7import sys8import pandas as pd9import numpy as np10from pathlib import Path11 12def test_directory_structure():13 """Test if the required directories exist"""14 # Ensure necessary directories exist15 os.makedirs('database/data', exist_ok=True)16 os.makedirs('assets', exist_ok=True)17 os.makedirs('fine_tuned_models', exist_ok=True)18 19 # Check if directories exist20 assert Path("database").exists() and Path("database").is_dir(), "Database directory not found"21 assert Path("assets").exists() and Path("assets").is_dir(), "Assets directory not found"22 assert Path("fine_tuned_models").exists() and Path("fine_tuned_models").is_dir(), "Fine-tuned models directory not found"23 24 print("✅ Directory structure test passed")25 26def test_css_file():27 """Test if the CSS file exists"""28 css_file = Path("assets/custom.css")29 assert css_file.exists() and css_file.is_file(), "CSS file not found in assets directory"30 31 print("✅ CSS file test passed")32 33def test_huggingface_config():34 """Test if Hugging Face configuration file exists"""35 config_file = Path("huggingface-spacefile")36 assert config_file.exists() and config_file.is_file(), "Hugging Face configuration file not found"37 38 print("✅ Hugging Face configuration test passed")39 40def test_streamlit_config():41 """Test if Streamlit configuration exists"""42 config_dir = Path(".streamlit")43 config_file = config_dir / "config.toml"44 assert config_dir.exists() and config_dir.is_dir(), ".streamlit directory not found"45 assert config_file.exists() and config_file.is_file(), "config.toml file not found in .streamlit directory"46 47 print("✅ Streamlit configuration test passed")48 49def test_sample_dataframe():50 """Test creation of sample dataframes"""51 # Create a sample dataframe52 df = pd.DataFrame({53 "code": ["def hello():", "import numpy as np", "print('Hello')"],54 "comment": ["Function greeting", "Import numpy library", "Print hello message"]55 })56 57 # Test dataframe properties58 assert len(df) == 359 assert list(df.columns) == ["code", "comment"]60 61 print("✅ Sample dataframe test passed")62 63def test_database_initialization():64 """Test if database can be initialized"""65 try:66 from database import init_db67 init_db()68 assert Path("database/data/mlmanager.db").exists(), "Database file was not created"69 print("✅ Database initialization test passed")70 except ImportError:71 print("⚠️ Could not import database module")72 assert False, "Database module not found"73 74def run_tests():75 """Run all tests"""76 print("Running tests for ML Dataset & Code Generation Manager...")77 78 test_directory_structure()79 test_css_file()80 test_huggingface_config()81 test_streamlit_config()82 test_sample_dataframe()83 test_database_initialization()84 85 print("\nAll tests passed! ✅")86 87def test_components_existence():88 """Test if core components directories exist"""89 # Check for components directory90 components_dir = Path("components")91 assert components_dir.exists() and components_dir.is_dir(), "Components directory not found"92 93 # Check for fine_tuning subdirectory94 fine_tuning_dir = components_dir / "fine_tuning"95 assert fine_tuning_dir.exists() and fine_tuning_dir.is_dir(), "Fine-tuning components directory not found"96 97 # Check for essential component files98 assert (components_dir / "code_quality.py").exists(), "Code quality component not found"99 assert (components_dir / "dataset_uploader.py").exists(), "Dataset uploader component not found"100 101 print("✅ Components existence test passed")102 103# Run the tests if executed directly104if __name__ == '__main__':105 run_tests()