File size: 1,484 Bytes
558d330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import sys, io, os
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
sys.path.insert(0, '.')

from pipeline.resolver import resolve
from pipeline.fetcher import fetch_all
from pipeline.calculator import calculate
from pipeline.analyst import generate_narrative
from builders.build_excel import build_workbook
from builders.build_docx import build_document

def run_test():
    print("1. Resolving TCS...")
    meta = resolve('TCS', log_fn=lambda m: print("  " + m))
    
    print("\n2. Fetching data...")
    data = fetch_all(meta, years=5, force_refresh=False, log_fn=lambda m: print("  " + m))
    
    print("\n3. Calculating ratios...")
    data = calculate(data, meta.to_dict())
    
    print("\n4. Generating Narrative (Data-only)...")
    # Use empty models list to skip actual API calls for a quick formatting test
    narrative = generate_narrative(data, meta.to_dict(), models=[], log_fn=lambda m: print("  " + m))
    data.update(narrative)
    
    # Save test files
    os.makedirs("test_outputs", exist_ok=True)
    excel_path = "test_outputs/TCS_Analysis.xlsx"
    docx_path = "test_outputs/TCS_Analysis.docx"
    
    print("\n5. Building Excel...")
    build_workbook(data, excel_path)
    print(f"  ✓ Saved to {excel_path}")
    
    print("\n6. Building Word Document...")
    build_document(data, docx_path)
    print(f"  ✓ Saved to {docx_path}")
    
    print("\nAll tests passed successfully!")

if __name__ == "__main__":
    run_test()