Spaces:
Runtime error
Runtime error
File size: 5,915 Bytes
d18c374 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
#!/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())
|