File size: 1,575 Bytes
a543e33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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)