Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
""" | |
Test script for mode handling in the enhanced pronunciation assessment system | |
""" | |
import sys | |
import os | |
# Add the src directory to the path | |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src')) | |
from apis.controllers.speaking_controller import ( | |
SimplePronunciationAssessor, | |
EnhancedPronunciationAssessor | |
) | |
def test_mode_handling(): | |
"""Test that the mode handling works correctly""" | |
print("Testing mode handling...") | |
# Test EnhancedPronunciationAssessor | |
enhanced_assessor = EnhancedPronunciationAssessor() | |
# Test with valid modes | |
test_cases = [ | |
("word", "hello"), | |
("sentence", "hello world how are you"), | |
("auto", "test"), | |
("invalid", "test") # This should default to auto | |
] | |
for mode, text in test_cases: | |
try: | |
# We won't actually run the assessment, just test the mode handling | |
# by checking the mode mapping logic | |
print(f"Testing mode '{mode}' with text '{text}'") | |
# Simulate the mode validation logic | |
valid_modes = ["word", "sentence", "auto"] | |
if mode not in valid_modes: | |
print(f" Invalid mode '{mode}' would be mapped to 'auto'") | |
else: | |
print(f" Valid mode '{mode}' accepted") | |
except Exception as e: | |
print(f" Error testing mode '{mode}': {e}") | |
# Test SimplePronunciationAssessor (backward compatibility) | |
simple_assessor = SimplePronunciationAssessor() | |
old_modes = ["normal", "advanced"] | |
for mode in old_modes: | |
try: | |
print(f"Testing backward compatible mode '{mode}'") | |
# Simulate the mode mapping logic | |
mode_mapping = { | |
"normal": "auto", | |
"advanced": "auto" | |
} | |
if mode in mode_mapping: | |
new_mode = mode_mapping[mode] | |
print(f" Old mode '{mode}' mapped to new mode '{new_mode}'") | |
else: | |
print(f" Mode '{mode}' not in mapping") | |
except Exception as e: | |
print(f" Error testing backward compatible mode '{mode}': {e}") | |
print("Mode handling test completed successfully!") | |
if __name__ == "__main__": | |
test_mode_handling() |