|
|
|
|
|
""" |
|
|
Basic test to verify the cleaned up phoneme detection leaderboard functionality. |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
import json |
|
|
import tempfile |
|
|
import pandas as pd |
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
|
def test_imports(): |
|
|
"""Test that all modules can be imported""" |
|
|
try: |
|
|
from constants import BANNER, INTRODUCTION_TEXT |
|
|
from utils_display import PhonemeEvalColumn, make_clickable_model |
|
|
from init import is_model_on_hub |
|
|
print("All imports successful") |
|
|
return True |
|
|
except ImportError as e: |
|
|
print(f"Import error: {e}") |
|
|
return False |
|
|
|
|
|
def test_data_loading(): |
|
|
"""Test that the app can load data from eval-results directory""" |
|
|
try: |
|
|
from app import load_results, EVAL_RESULTS_DIR |
|
|
|
|
|
|
|
|
os.makedirs(EVAL_RESULTS_DIR, exist_ok=True) |
|
|
test_result = { |
|
|
"config": { |
|
|
"model_name": "test/model", |
|
|
"model_dtype": "float32", |
|
|
"model_sha": "test123" |
|
|
}, |
|
|
"results": { |
|
|
"phoneme_asr": {"per": 15.5, "avg_duration": 0.1}, |
|
|
"kids_phoneme_md": {"per": 18.2, "avg_duration": 0.12} |
|
|
} |
|
|
} |
|
|
|
|
|
test_file = os.path.join(EVAL_RESULTS_DIR, "test_results.json") |
|
|
with open(test_file, "w") as f: |
|
|
json.dump(test_result, f) |
|
|
|
|
|
|
|
|
df = load_results(EVAL_RESULTS_DIR) |
|
|
print(f"Data loading successful, found {len(df)} rows") |
|
|
|
|
|
|
|
|
os.remove(test_file) |
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
print(f"Data loading error: {e}") |
|
|
return False |
|
|
|
|
|
def test_utils(): |
|
|
"""Test utility functions""" |
|
|
try: |
|
|
from utils_display import make_clickable_model, styled_error, styled_message |
|
|
|
|
|
|
|
|
link = make_clickable_model("facebook/hubert-base") |
|
|
assert "facebook/hubert-base" in link |
|
|
assert "href=" in link |
|
|
|
|
|
|
|
|
error_msg = styled_error("Test error") |
|
|
assert "red" in error_msg |
|
|
|
|
|
success_msg = styled_message("Test success") |
|
|
assert "green" in success_msg |
|
|
|
|
|
print("Utility functions working") |
|
|
return True |
|
|
|
|
|
except Exception as e: |
|
|
print(f"Utility test error: {e}") |
|
|
return False |
|
|
|
|
|
def main(): |
|
|
"""Run all tests""" |
|
|
print("Testing Phoneme Detection Leaderboard...") |
|
|
|
|
|
tests = [ |
|
|
test_imports, |
|
|
test_data_loading, |
|
|
test_utils |
|
|
] |
|
|
|
|
|
passed = 0 |
|
|
total = len(tests) |
|
|
|
|
|
for test in tests: |
|
|
if test(): |
|
|
passed += 1 |
|
|
print() |
|
|
|
|
|
print(f"Test Results: {passed}/{total} tests passed") |
|
|
|
|
|
if passed == total: |
|
|
print("All tests passed! The cleaned up version is working correctly.") |
|
|
return True |
|
|
else: |
|
|
print("Some tests failed. Please check the errors above.") |
|
|
return False |
|
|
|
|
|
if __name__ == "__main__": |
|
|
success = main() |
|
|
sys.exit(0 if success else 1) |
|
|
|