#!/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()