"""
简单的测试脚本来验证服务器功能
"""
import json
from loader import DataStandardLoader

def test_loader():
    """测试数据标准加载器"""
    print("测试数据标准加载器...")
    
    loader = DataStandardLoader()
    
    # 测试列出 schema 名称
    print("\n1. 测试 list_schema_names()...")
    try:
        names = loader.list_schema_names()
        print(f"   找到 {len(names)} 个 schema")
        if names:
            print(f"   示例: {names[:3]}")
        else:
            print("   警告: 没有找到任何 schema，请确保 schemas 目录中有 JSON 文件")
    except Exception as e:
        print(f"   错误: {e}")
    
    # 测试获取 schema 描述
    print("\n2. 测试 describe_schemas()...")
    try:
        if names and len(names) > 0:
            test_names = names[:2] if len(names) >= 2 else names
            descriptions = loader.describe_schemas(test_names)
            print(f"   获取 {len(descriptions)} 个 schema 的描述")
            for name, desc in descriptions.items():
                print(f"   {name}: {desc[:50]}...")
        else:
            print("   跳过: 没有可用的 schema")
    except Exception as e:
        print(f"   错误: {e}")
    
    # 测试获取 schema 字段定义
    print("\n3. 测试 get_schema()...")
    try:
        if names and len(names) > 0:
            test_path = names[0]
            schema = loader.get_schema(test_path)
            if schema:
                print(f"   成功获取 schema: {test_path}")
                print(f"   字段数量: {len(schema)}")
                if schema:
                    first_field = list(schema.keys())[0]
                    print(f"   示例字段: {first_field}")
            else:
                print(f"   警告: 无法获取 schema: {test_path}")
        else:
            print("   跳过: 没有可用的 schema")
    except Exception as e:
        print(f"   错误: {e}")
    
    print("\n测试完成！")

if __name__ == "__main__":
    test_loader()


