Spaces:
Building
Building
File size: 5,962 Bytes
e7279e4 |
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 |
#!/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())
|