Download verify_compatibility.py from JatinAutonomousLabs/HonestAI: direct link, hf CLI and curl.
- Browser
- Download file 6.09 kB
-
https://huggingface.co/spaces/JatinAutonomousLabs/HonestAI/resolve/main/verify_compatibility.py
- Command line
-
hf download hf://spaces/JatinAutonomousLabs/HonestAI/verify_compatibility.py
-
curl -L -o verify_compatibility.py https://huggingface.co/spaces/JatinAutonomousLabs/HonestAI/resolve/main/verify_compatibility.py
6.09 kB
| #!/usr/bin/env python3 | |
| """ | |
| Backward Compatibility Verification Script | |
| This script verifies that the enhanced config.py maintains 100% backward | |
| compatibility with existing code and API calls. | |
| """ | |
| import sys | |
| import os | |
| def test_imports(): | |
| """Test that all import patterns work""" | |
| print("=" * 60) | |
| print("Testing Import Patterns") | |
| print("=" * 60) | |
| # Test 1: from config import settings | |
| try: | |
| from config import settings | |
| assert hasattr(settings, 'hf_token') | |
| assert hasattr(settings, 'hf_cache_dir') | |
| assert hasattr(settings, 'db_path') | |
| print("β 'from config import settings' - PASSED") | |
| except Exception as e: | |
| print(f"β 'from config import settings' - FAILED: {e}") | |
| return False | |
| # Test 2: from src.config import settings | |
| try: | |
| from src.config import settings | |
| assert hasattr(settings, 'hf_token') | |
| assert hasattr(settings, 'hf_cache_dir') | |
| print("β 'from src.config import settings' - PASSED") | |
| except Exception as e: | |
| print(f"β 'from src.config import settings' - FAILED: {e}") | |
| return False | |
| # Test 3: from .config import settings (relative import) | |
| try: | |
| import src | |
| from src.config import settings | |
| assert hasattr(settings, 'hf_token') | |
| print("β Relative import - PASSED") | |
| except Exception as e: | |
| print(f"β Relative import - FAILED: {e}") | |
| return False | |
| return True | |
| def test_attributes(): | |
| """Test that all attributes work as expected""" | |
| print("\n" + "=" * 60) | |
| print("Testing Attribute Access") | |
| print("=" * 60) | |
| from config import settings | |
| # Test hf_token | |
| try: | |
| token = settings.hf_token | |
| assert isinstance(token, str) | |
| print(f"β settings.hf_token: {type(token).__name__} - PASSED") | |
| except Exception as e: | |
| print(f"β settings.hf_token - FAILED: {e}") | |
| return False | |
| # Test hf_cache_dir | |
| try: | |
| cache_dir = settings.hf_cache_dir | |
| assert isinstance(cache_dir, str) | |
| assert len(cache_dir) > 0 | |
| print(f"β settings.hf_cache_dir: {cache_dir} - PASSED") | |
| except Exception as e: | |
| print(f"β settings.hf_cache_dir - FAILED: {e}") | |
| return False | |
| # Test db_path | |
| try: | |
| db_path = settings.db_path | |
| assert isinstance(db_path, str) | |
| print(f"β settings.db_path: {db_path} - PASSED") | |
| except Exception as e: | |
| print(f"β settings.db_path - FAILED: {e}") | |
| return False | |
| # Test max_workers | |
| try: | |
| max_workers = settings.max_workers | |
| assert isinstance(max_workers, int) | |
| assert 1 <= max_workers <= 16 | |
| print(f"β settings.max_workers: {max_workers} - PASSED") | |
| except Exception as e: | |
| print(f"β settings.max_workers - FAILED: {e}") | |
| return False | |
| # Test all other attributes | |
| attributes = [ | |
| 'cache_ttl', 'faiss_index_path', 'session_timeout', | |
| 'max_session_size_mb', 'mobile_max_tokens', 'mobile_timeout', | |
| 'gradio_port', 'gradio_host', 'log_level', 'log_format', | |
| 'default_model', 'embedding_model', 'classification_model' | |
| ] | |
| for attr in attributes: | |
| try: | |
| value = getattr(settings, attr) | |
| print(f"β settings.{attr}: {type(value).__name__} - PASSED") | |
| except Exception as e: | |
| print(f"β settings.{attr} - FAILED: {e}") | |
| return False | |
| return True | |
| def test_context_manager_compatibility(): | |
| """Test that context_manager can import settings""" | |
| print("\n" + "=" * 60) | |
| print("Testing Context Manager Compatibility") | |
| print("=" * 60) | |
| try: | |
| # Simulate what context_manager does | |
| from config import settings | |
| db_path = settings.db_path | |
| assert isinstance(db_path, str) | |
| print(f"β Context manager import pattern works - PASSED") | |
| print(f" db_path: {db_path}") | |
| return True | |
| except Exception as e: | |
| print(f"β Context manager compatibility - FAILED: {e}") | |
| return False | |
| def test_cache_directory(): | |
| """Test cache directory functionality""" | |
| print("\n" + "=" * 60) | |
| print("Testing Cache Directory Management") | |
| print("=" * 60) | |
| try: | |
| from src.config import settings | |
| cache_dir = settings.hf_cache_dir | |
| # Verify directory exists | |
| assert os.path.exists(cache_dir), f"Cache directory does not exist: {cache_dir}" | |
| print(f"β Cache directory exists: {cache_dir}") | |
| # Verify write access | |
| test_file = os.path.join(cache_dir, ".test_write") | |
| try: | |
| with open(test_file, 'w') as f: | |
| f.write("test") | |
| os.remove(test_file) | |
| print(f"β Cache directory is writable") | |
| except PermissionError: | |
| print(f"β οΈ Cache directory not writable (may need permissions)") | |
| return True | |
| except Exception as e: | |
| print(f"β Cache directory test - FAILED: {e}") | |
| return False | |
| def main(): | |
| """Run all compatibility tests""" | |
| print("Backward Compatibility Verification") | |
| print("=" * 60) | |
| print() | |
| results = [] | |
| results.append(("Imports", test_imports())) | |
| results.append(("Attributes", test_attributes())) | |
| results.append(("Context Manager", test_context_manager_compatibility())) | |
| results.append(("Cache Directory", test_cache_directory())) | |
| print("\n" + "=" * 60) | |
| print("Test Summary") | |
| print("=" * 60) | |
| all_passed = True | |
| for test_name, passed in results: | |
| status = "β PASSED" if passed else "β FAILED" | |
| print(f"{test_name}: {status}") | |
| if not passed: | |
| all_passed = False | |
| print("=" * 60) | |
| if all_passed: | |
| print("β ALL TESTS PASSED - Backward compatibility verified!") | |
| return 0 | |
| else: | |
| print("β SOME TESTS FAILED - Please review errors above") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |