Spaces:
Building
Building
| #!/usr/bin/env python3 | |
| """ | |
| Test frontend functions for YAML configuration. | |
| """ | |
| import sys | |
| import os | |
| sys.path.append(os.path.join(os.path.dirname(__file__), 'frontend')) | |
| # Mock streamlit cache decorator | |
| class MockCache: | |
| def __call__(self, func): | |
| return func | |
| # Mock streamlit module | |
| class MockStreamlit: | |
| cache_data = MockCache() | |
| def error(self, msg): | |
| print(f"[ERROR] {msg}") | |
| sys.modules['streamlit'] = MockStreamlit() | |
| def test_frontend_functions(): | |
| """Test frontend YAML functions.""" | |
| print("Testing Frontend YAML Functions...") | |
| try: | |
| # Now import after mocking | |
| from app import load_reference_config, load_reference_list_data | |
| # Test loading config | |
| config = load_reference_config() | |
| print("β YAML config loaded successfully") | |
| print(f"β English unigrams: {list(config['english']['unigrams'].keys())}") | |
| # Test loading reference data | |
| coca_config = config['english']['unigrams']['COCA_spoken_frequency'] | |
| data = load_reference_list_data(coca_config) | |
| print(f"β COCA data loaded: {len(data)} file types") | |
| for file_type, file_data in data.items(): | |
| print(f" - {file_type}: {len(file_data)} entries") | |
| return True | |
| except Exception as e: | |
| print(f"β Frontend functions test failed: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return False | |
| if __name__ == "__main__": | |
| success = test_frontend_functions() | |
| sys.exit(0 if success else 1) |