morris-bot / test_setup.py
eusholli's picture
Upload folder using huggingface_hub
599c2c0 verified
#!/usr/bin/env python3
"""
Test script to verify project setup and dependencies
"""
import sys
import os
import importlib
from pathlib import Path
def test_python_version():
"""Test Python version"""
print("🐍 Python Version Check")
version = sys.version_info
print(f" Python {version.major}.{version.minor}.{version.micro}")
if version.major >= 3 and version.minor >= 8:
print(" βœ… Python version OK")
return True
else:
print(" ❌ Python 3.8+ required")
return False
def test_dependencies():
"""Test required dependencies"""
print("\nπŸ“¦ Dependency Check")
required_packages = [
'requests',
'beautifulsoup4',
'pandas',
'numpy',
'tqdm',
'gradio'
]
optional_packages = [
'torch',
'transformers',
'datasets',
'peft',
'bitsandbytes',
'accelerate'
]
all_good = True
for package in required_packages:
try:
importlib.import_module(package)
print(f" βœ… {package}")
except ImportError:
print(f" ❌ {package} (required)")
all_good = False
print("\n Optional ML packages:")
for package in optional_packages:
try:
importlib.import_module(package)
print(f" βœ… {package}")
except ImportError:
print(f" ⚠️ {package} (optional, needed for training)")
return all_good
def test_project_structure():
"""Test project file structure"""
print("\nπŸ“ Project Structure Check")
required_files = [
'requirements.txt',
'app.py',
'run_pipeline.py',
'README.md',
'src/scraper.py',
'src/preprocess.py',
'src/finetune.py',
'src/utils.py'
]
required_dirs = [
'src',
'data',
'models',
'models/lora_adapters'
]
all_good = True
for file_path in required_files:
if os.path.exists(file_path):
print(f" βœ… {file_path}")
else:
print(f" ❌ {file_path}")
all_good = False
for dir_path in required_dirs:
if os.path.exists(dir_path):
print(f" βœ… {dir_path}/")
else:
print(f" ❌ {dir_path}/")
all_good = False
return all_good
def test_gpu_availability():
"""Test GPU availability"""
print("\nπŸ–₯️ Hardware Check")
try:
import torch
print(f" PyTorch version: {torch.__version__}")
if torch.cuda.is_available():
gpu_count = torch.cuda.device_count()
print(f" βœ… CUDA available ({gpu_count} GPU(s))")
for i in range(gpu_count):
props = torch.cuda.get_device_properties(i)
memory_gb = props.total_memory / 1e9
print(f" GPU {i}: {props.name} ({memory_gb:.1f} GB)")
return True
else:
print(" ⚠️ CUDA not available (CPU training only)")
return False
except ImportError:
print(" ❌ PyTorch not installed")
return False
def test_internet_connection():
"""Test internet connectivity"""
print("\n🌐 Internet Connection Check")
try:
import requests
response = requests.get('https://www.lightreading.com', timeout=10)
if response.status_code == 200:
print(" βœ… Light Reading accessible")
return True
else:
print(f" ⚠️ Light Reading returned status {response.status_code}")
return False
except Exception as e:
print(f" ❌ Internet connection failed: {e}")
return False
def run_basic_import_test():
"""Test basic imports from project modules"""
print("\nπŸ”§ Module Import Check")
sys.path.append(str(Path(__file__).parent / "src"))
modules_to_test = [
('scraper', 'LightReadingScraper'),
('preprocess', 'ArticlePreprocessor'),
('utils', 'setup_logging')
]
all_good = True
for module_name, class_name in modules_to_test:
try:
module = importlib.import_module(module_name)
getattr(module, class_name)
print(f" βœ… {module_name}.{class_name}")
except Exception as e:
print(f" ❌ {module_name}.{class_name}: {e}")
all_good = False
return all_good
def main():
"""Run all tests"""
print("πŸ§ͺ MORRIS-BOT PROJECT SETUP TEST")
print("=" * 50)
tests = [
("Python Version", test_python_version),
("Dependencies", test_dependencies),
("Project Structure", test_project_structure),
("GPU Availability", test_gpu_availability),
("Internet Connection", test_internet_connection),
("Module Imports", run_basic_import_test)
]
results = []
for test_name, test_func in tests:
try:
result = test_func()
results.append((test_name, result))
except Exception as e:
print(f" ❌ Test failed with error: {e}")
results.append((test_name, False))
# Summary
print("\n" + "=" * 50)
print("πŸ“Š TEST SUMMARY")
print("=" * 50)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "βœ… PASS" if result else "❌ FAIL"
print(f" {status} {test_name}")
print(f"\nOverall: {passed}/{total} tests passed")
if passed == total:
print("\nπŸŽ‰ All tests passed! Your setup is ready.")
print("\nNext steps:")
print(" 1. Run: python run_pipeline.py --status")
print(" 2. Run: python run_pipeline.py --collect")
else:
print("\n⚠️ Some tests failed. Please check the issues above.")
print("\nCommon fixes:")
print(" - Install missing packages: pip install -r requirements.txt")
print(" - Check internet connection")
print(" - Install PyTorch for GPU support")
if __name__ == "__main__":
main()