Spaces:
Building
Building
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify the advanced selection UI implementation. | |
| """ | |
| import sys | |
| import os | |
| from pathlib import Path | |
| # Add project root to path | |
| project_root = Path(__file__).parent | |
| sys.path.insert(0, str(project_root)) | |
| def test_ui_components_grouping(): | |
| """Test the grouping functionality of UI components.""" | |
| print("Testing UI Components Grouping...") | |
| try: | |
| from web_app.components.ui_components import UIComponents | |
| from web_app.config_manager import ConfigManager | |
| # Load the configuration | |
| config = ConfigManager.load_reference_config() | |
| # Simulate reference lists | |
| mock_reference_lists = { | |
| 'COCA_spoken_frequency_token': {}, | |
| 'COCA_spoken_frequency_lemma': {}, | |
| 'concreteness_ratings_token': {}, | |
| 'concreteness_ratings_lemma': {} | |
| } | |
| # Test grouping function | |
| groups = UIComponents._group_reference_lists(mock_reference_lists, config) | |
| print(f"β Grouping successful! Found {len(groups)} groups:") | |
| for base_name, group_data in groups.items(): | |
| token_count = len(group_data['token']) | |
| lemma_count = len(group_data['lemma']) | |
| print(f" - {base_name}: {token_count} token entries, {lemma_count} lemma entries") | |
| return True | |
| except Exception as e: | |
| print(f"β Grouping test failed: {e}") | |
| return False | |
| def test_config_structure(): | |
| """Test that the configuration has the expected structure.""" | |
| print("\nTesting Configuration Structure...") | |
| try: | |
| from web_app.config_manager import ConfigManager | |
| config = ConfigManager.load_reference_config() | |
| # Check for expected keys | |
| expected_sections = ['english', 'japanese'] | |
| found_sections = [] | |
| for section in expected_sections: | |
| if section in config: | |
| found_sections.append(section) | |
| print(f" β Found {section} section") | |
| # Check for subsections | |
| for subsection in ['unigrams', 'bigrams', 'trigrams']: | |
| if subsection in config[section]: | |
| entries = len(config[section][subsection]) | |
| print(f" - {subsection}: {entries} entries") | |
| if found_sections: | |
| print(f"β Configuration structure valid!") | |
| # Check for advanced selection fields | |
| sample_entry = None | |
| for lang in config.values(): | |
| if isinstance(lang, dict): | |
| for ngram_type in lang.values(): | |
| if isinstance(ngram_type, dict): | |
| for entry_name, entry_config in ngram_type.items(): | |
| sample_entry = entry_config | |
| break | |
| break | |
| break | |
| if sample_entry: | |
| required_fields = ['selectable_measures', 'default_measures', 'default_log_transforms', 'log_transformable'] | |
| missing_fields = [] | |
| for field in required_fields: | |
| if field not in sample_entry: | |
| missing_fields.append(field) | |
| else: | |
| print(f" β Found {field}: {sample_entry[field]}") | |
| if missing_fields: | |
| print(f" β οΈ Missing fields: {missing_fields}") | |
| else: | |
| print(" β All advanced selection fields present!") | |
| return True | |
| else: | |
| print("β No valid configuration sections found") | |
| return False | |
| except Exception as e: | |
| print(f"β Configuration test failed: {e}") | |
| return False | |
| def test_analyzer_parameters(): | |
| """Test that the analyzer accepts the new parameters.""" | |
| print("\nTesting Analyzer Parameters...") | |
| try: | |
| from text_analyzer.lexical_sophistication import LexicalSophisticationAnalyzer | |
| # Create analyzer | |
| analyzer = LexicalSophisticationAnalyzer(language='en', model_size='md') | |
| # Test parameter signature | |
| import inspect | |
| analyze_signature = inspect.signature(analyzer.analyze_text) | |
| params = list(analyze_signature.parameters.keys()) | |
| required_params = ['log_transforms', 'selected_measures'] | |
| found_params = [] | |
| for param in required_params: | |
| if param in params: | |
| found_params.append(param) | |
| print(f" β Found parameter: {param}") | |
| else: | |
| print(f" β Missing parameter: {param}") | |
| if len(found_params) == len(required_params): | |
| print("β Analyzer has all required parameters!") | |
| return True | |
| else: | |
| print(f"β Analyzer missing {len(required_params) - len(found_params)} parameters") | |
| return False | |
| except Exception as e: | |
| print(f"β Analyzer test failed: {e}") | |
| return False | |
| def main(): | |
| """Run all tests.""" | |
| print("π§ͺ Testing Advanced Selection Implementation\n") | |
| tests = [ | |
| test_config_structure, | |
| test_ui_components_grouping, | |
| test_analyzer_parameters | |
| ] | |
| passed = 0 | |
| total = len(tests) | |
| for test in tests: | |
| if test(): | |
| passed += 1 | |
| print(f"\nπ Test Results: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("π All tests passed! Advanced selection implementation is ready.") | |
| return 0 | |
| else: | |
| print("β οΈ Some tests failed. Please check the implementation.") | |
| return 1 | |
| if __name__ == "__main__": | |
| exit(main()) | |