ShopTRAINING/test/test_fixed_path.py
2025-07-02 11:05:23 +08:00

47 lines
1.3 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
"""
测试修复后的路径
"""
import sys
import os
sys.path.append('server')
def test_from_server_dir():
"""从server目录模拟API调用"""
# 模拟API服务器从server目录运行
original_cwd = os.getcwd()
try:
# 切换到server目录
server_dir = os.path.join(os.getcwd(), 'server')
os.chdir(server_dir)
print(f"切换到server目录: {os.getcwd()}")
# 添加当前目录到路径server目录
if server_dir not in sys.path:
sys.path.insert(0, server_dir)
# 导入模型管理器
from utils.model_manager import model_manager
print(f"模型目录: {model_manager.model_dir}")
print(f"模型目录存在: {os.path.exists(model_manager.model_dir)}")
# 测试模型列表
models = model_manager.list_models()
print(f"找到模型: {len(models)}")
if models:
model = models[0]
print(f"模型文件名: {model.get('filename')}")
print(f"产品名称: {model.get('product_name')}")
return len(models) > 0
finally:
# 恢复原始工作目录
os.chdir(original_cwd)
if __name__ == "__main__":
test_from_server_dir()