Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script for SHL Assessment Recommender System | |
| Tests basic functionality without requiring full model downloads. | |
| """ | |
| import sys | |
| import os | |
| def test_imports(): | |
| """Test that all modules can be imported""" | |
| print("Testing imports...") | |
| try: | |
| import pandas | |
| import numpy | |
| import sklearn | |
| from bs4 import BeautifulSoup | |
| import requests | |
| print("β Data processing packages") | |
| except ImportError as e: | |
| print(f"β Data processing packages: {e}") | |
| return False | |
| try: | |
| from src import crawler, preprocess | |
| print("β Core modules (crawler, preprocess)") | |
| except ImportError as e: | |
| print(f"β Core modules: {e}") | |
| return False | |
| try: | |
| import fastapi | |
| import uvicorn | |
| import streamlit | |
| print("β API and UI packages") | |
| except ImportError as e: | |
| print(f"β API and UI packages: {e}") | |
| return False | |
| return True | |
| def test_data_files(): | |
| """Test that required data files exist""" | |
| print("\nTesting data files...") | |
| # Check training data | |
| if os.path.exists('Data/Gen_AI Dataset.xlsx'): | |
| print("β Training dataset found") | |
| else: | |
| print("β Training dataset not found (Data/Gen_AI Dataset.xlsx)") | |
| # Check catalog | |
| if os.path.exists('data/shl_catalog.csv'): | |
| print("β SHL catalog found") | |
| import pandas as pd | |
| df = pd.read_csv('data/shl_catalog.csv') | |
| print(f" - {len(df)} assessments") | |
| print(f" - K assessments: {len(df[df['test_type'] == 'K'])}") | |
| print(f" - P assessments: {len(df[df['test_type'] == 'P'])}") | |
| else: | |
| print("β SHL catalog not found (run: python src/crawler.py)") | |
| return True | |
| def test_crawler(): | |
| """Test the crawler module""" | |
| print("\nTesting crawler...") | |
| try: | |
| from src.crawler import SHLCrawler | |
| crawler = SHLCrawler() | |
| # Test text classification | |
| assert crawler.determine_test_type("Java programming test") == "K" | |
| assert crawler.determine_test_type("Personality assessment") == "P" | |
| print("β Test type classification works") | |
| # Test category extraction | |
| cat = crawler.extract_category("Leadership management") | |
| assert cat == "Leadership" | |
| print("β Category extraction works") | |
| return True | |
| except Exception as e: | |
| print(f"β Crawler test failed: {e}") | |
| return False | |
| def test_preprocessor(): | |
| """Test the preprocessor module""" | |
| print("\nTesting preprocessor...") | |
| try: | |
| from src.preprocess import DataPreprocessor | |
| preprocessor = DataPreprocessor() | |
| # Test text cleaning | |
| clean = preprocessor.clean_text(" Hello, WORLD! ") | |
| assert clean == "hello, world!" | |
| print("β Text cleaning works") | |
| # Test URL extraction | |
| urls = preprocessor.extract_urls_from_text("Check https://example.com and http://test.com") | |
| assert len(urls) == 2 | |
| print("β URL extraction works") | |
| return True | |
| except Exception as e: | |
| print(f"β Preprocessor test failed: {e}") | |
| return False | |
| def test_api_structure(): | |
| """Test that API is properly structured""" | |
| print("\nTesting API structure...") | |
| try: | |
| from api.main import app | |
| # Check endpoints exist | |
| routes = [route.path for route in app.routes] | |
| assert "/health" in routes | |
| print("β /health endpoint exists") | |
| assert "/recommend" in routes | |
| print("β /recommend endpoint exists") | |
| return True | |
| except Exception as e: | |
| print(f"β API structure test failed: {e}") | |
| return False | |
| def test_streamlit_app(): | |
| """Test that Streamlit app can be imported""" | |
| print("\nTesting Streamlit app...") | |
| try: | |
| # Just check the file exists and is valid Python | |
| with open('app.py', 'r') as f: | |
| content = f.read() | |
| assert 'st.set_page_config' in content | |
| print("β Streamlit app file valid") | |
| assert 'SHL Assessment Recommender' in content | |
| print("β App title configured") | |
| return True | |
| except Exception as e: | |
| print(f"β Streamlit app test failed: {e}") | |
| return False | |
| def main(): | |
| """Run all tests""" | |
| print("="*60) | |
| print("SHL ASSESSMENT RECOMMENDER - BASIC TESTS") | |
| print("="*60) | |
| tests = [ | |
| ("Imports", test_imports), | |
| ("Data Files", test_data_files), | |
| ("Crawler", test_crawler), | |
| ("Preprocessor", test_preprocessor), | |
| ("API Structure", test_api_structure), | |
| ("Streamlit App", test_streamlit_app) | |
| ] | |
| results = [] | |
| for test_name, test_func in tests: | |
| try: | |
| result = test_func() | |
| results.append((test_name, result)) | |
| except Exception as e: | |
| print(f"\nβ {test_name} failed with exception: {e}") | |
| results.append((test_name, False)) | |
| # Summary | |
| print("\n" + "="*60) | |
| print("TEST SUMMARY") | |
| print("="*60) | |
| 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"\nTotal: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("\nβ All basic tests passed!") | |
| print("\nNote: Full system tests require:") | |
| print(" - Internet connection (for model downloads)") | |
| print(" - Running: python setup.py") | |
| return 0 | |
| else: | |
| print("\nβ Some tests failed") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |