Spaces:
Sleeping
Sleeping
Riley
feat: Major scraper enhancements - consistent format, better extraction, per-month costs
2ae7490 | #!/usr/bin/env python3 | |
| """ | |
| Verification script for Grant Analyst setup. | |
| Tests that all core components can be imported and initialized. | |
| Run this before deployment to catch configuration issues. | |
| """ | |
| import sys | |
| from pathlib import Path | |
| # Add src to path for local development | |
| sys.path.insert(0, str(Path(__file__).parent / "src")) | |
| def test_imports(): | |
| """Test that core modules can be imported.""" | |
| print("Testing imports...") | |
| try: | |
| from analyzer.config import get_settings | |
| print("β Config module imported") | |
| except Exception as e: | |
| print(f"β Failed to import config: {e}") | |
| return False | |
| try: | |
| from analyzer.models import Grant, QARequest, SearchFilters | |
| print("β Models module imported") | |
| except Exception as e: | |
| print(f"β Failed to import models: {e}") | |
| return False | |
| try: | |
| from analyzer.llm_client import LLMClient | |
| print("β LLM client module imported") | |
| except Exception as e: | |
| print(f"β Failed to import LLM client: {e}") | |
| return False | |
| try: | |
| from analyzer.search.service import search_grants | |
| print("β Search service module imported") | |
| except Exception as e: | |
| print(f"β Failed to import search service: {e}") | |
| return False | |
| try: | |
| from analyzer.qa_service import stream_answer | |
| print("β QA service module imported") | |
| except Exception as e: | |
| print(f"β Failed to import QA service: {e}") | |
| return False | |
| return True | |
| def test_config(): | |
| """Test that config can be loaded.""" | |
| print("\nTesting configuration...") | |
| try: | |
| from analyzer.config import get_settings | |
| settings = get_settings() | |
| print(f"β Settings loaded successfully") | |
| print(f" ENV: {settings.ENV}") | |
| print(f" LLM_PROVIDER: {settings.LLM_PROVIDER}") | |
| print(f" LLM_MODEL_QA: {settings.LLM_MODEL_QA}") | |
| print(f" MAX_QUERY_CHARS: {settings.MAX_QUERY_CHARS}") | |
| print(f" ALLOWED_ORIGINS: {settings.ALLOWED_ORIGINS}") | |
| if settings.ENV != "dev" and not settings.ALLOWED_ORIGINS: | |
| print(" β Warning: ALLOWED_ORIGINS not set for non-dev environment") | |
| return True | |
| except Exception as e: | |
| print(f"β Config validation failed: {e}") | |
| return False | |
| def test_models(): | |
| """Test that Pydantic models work.""" | |
| print("\nTesting Pydantic models...") | |
| try: | |
| from analyzer.models import Grant, QARequest, dict_to_grant | |
| # Test Grant model | |
| grant_dict = { | |
| "id": "test-123", | |
| "title": "Test Grant", | |
| "url": "https://example.com", | |
| "open_date": "2025-01-01", | |
| "close_date": "2025-12-31", | |
| } | |
| grant = dict_to_grant(grant_dict) | |
| print(f"β Grant model validation works") | |
| print(f" Created grant: {grant.id} - {grant.title}") | |
| # Test QARequest model | |
| request = QARequest(query="Test query", session_id="test-session") | |
| print(f"β QARequest model validation works") | |
| return True | |
| except Exception as e: | |
| print(f"β Model validation failed: {e}") | |
| return False | |
| def test_legacy_compatibility(): | |
| """Test that legacy code still works.""" | |
| print("\nTesting legacy compatibility...") | |
| try: | |
| from analyzer.config import load_config | |
| import warnings | |
| # Should work but emit deprecation warning | |
| with warnings.catch_warnings(record=True) as w: | |
| warnings.simplefilter("always") | |
| config = load_config() | |
| if w: | |
| print(f"β Legacy load_config() works (with deprecation warning)") | |
| else: | |
| print(f"β Legacy load_config() works") | |
| # Check that it has expected attributes | |
| assert hasattr(config, 'provider') | |
| assert hasattr(config, 'model') | |
| print(f" Config provider: {config.provider}") | |
| return True | |
| except Exception as e: | |
| print(f"β Legacy compatibility failed: {e}") | |
| return False | |
| def main(): | |
| """Run all verification tests.""" | |
| print("=" * 60) | |
| print("Grant Analyst Setup Verification") | |
| print("=" * 60) | |
| tests = [ | |
| ("Imports", test_imports), | |
| ("Configuration", test_config), | |
| ("Models", test_models), | |
| ("Legacy Compatibility", test_legacy_compatibility), | |
| ] | |
| results = [] | |
| for name, test_func in tests: | |
| try: | |
| result = test_func() | |
| results.append((name, result)) | |
| except Exception as e: | |
| print(f"\nβ {name} test crashed: {e}") | |
| results.append((name, False)) | |
| print("\n" + "=" * 60) | |
| print("Summary") | |
| print("=" * 60) | |
| for name, passed in results: | |
| status = "β PASS" if passed else "β FAIL" | |
| print(f"{status}: {name}") | |
| all_passed = all(result for _, result in results) | |
| if all_passed: | |
| print("\nβ All verification tests passed!") | |
| print("The refactored codebase is ready to use.") | |
| return 0 | |
| else: | |
| print("\nβ Some tests failed. Please fix the issues above.") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |