File size: 4,237 Bytes
24437ee |
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
#!/usr/bin/env python3
"""
重构后的模块化代码测试脚本
验证各个模块的功能是否正常工作
"""
def test_imports():
"""测试模块导入"""
print("🔍 测试模块导入...")
try:
import config
print("✅ config.py - 配置模块导入成功")
print(f" APP_TITLE: {config.APP_TITLE}")
print(f" AVAILABLE_CHARACTERS: {config.AVAILABLE_CHARACTERS}")
except ImportError as e:
print(f"❌ config.py 导入失败: {e}")
try:
import installer
print("✅ installer.py - 安装器模块导入成功")
except ImportError as e:
print(f"❌ installer.py 导入失败: {e}")
try:
import tts_engine
print("✅ tts_engine.py - TTS引擎模块导入成功")
print(f" TTS接口实例: {type(tts_engine.tts_interface)}")
except ImportError as e:
print(f"❌ tts_engine.py 导入失败: {e}")
try:
import ui_utils
print("✅ ui_utils.py - UI工具模块导入成功")
except ImportError as e:
print(f"❌ ui_utils.py 导入失败: {e}")
try:
import app
print("✅ app.py - 主应用模块导入成功")
except ImportError as e:
print(f"❌ app.py 导入失败: {e}")
def test_configuration():
"""测试配置功能"""
print("\n🛠️ 测试配置功能...")
try:
from config import get_cache_dir, setup_environment, EXAMPLE_TEXTS
cache_dir = get_cache_dir()
print(f"✅ 缓存目录设置: {cache_dir}")
setup_environment()
print("✅ 环境变量设置完成")
print(f"✅ 示例文本数量: {len(EXAMPLE_TEXTS)}")
except Exception as e:
print(f"❌ 配置功能测试失败: {e}")
def test_tts_interface():
"""测试TTS接口"""
print("\n🎵 测试TTS接口...")
try:
from tts_engine import tts_interface
print(f"✅ TTS接口创建成功")
print(f" 可用角色: {tts_interface.available_characters}")
print(f" 缓存目录: {tts_interface.model_cache_dir}")
print(f" 安装错误: {tts_interface.install_error}")
# 测试文本预处理
test_text = "こんにちは"
processed = tts_interface.preprocess_text(test_text)
print(f"✅ 文本预处理测试: '{test_text}' -> '{processed}'")
# 测试系统信息
sys_info = tts_interface.get_system_info()
print(f"✅ 系统信息获取: {list(sys_info.keys())}")
except Exception as e:
print(f"❌ TTS接口测试失败: {e}")
def test_ui_functions():
"""测试UI函数"""
print("\n🖥️ 测试UI函数...")
try:
from ui_utils import clear_all, load_example, create_tts_wrapper
from tts_engine import tts_interface
# 测试清空函数
result = clear_all()
print(f"✅ clear_all(): {result}")
# 测试示例加载
result = load_example("テスト", "misono_mika")
print(f"✅ load_example(): {result}")
# 测试包装器创建
wrapper = create_tts_wrapper(tts_interface)
print(f"✅ TTS包装器创建: {type(wrapper)}")
except Exception as e:
print(f"❌ UI函数测试失败: {e}")
def test_gradio_interface():
"""测试Gradio界面创建"""
print("\n🌐 测试Gradio界面...")
try:
from app import create_interface
demo = create_interface()
print(f"✅ Gradio界面创建成功: {type(demo)}")
except Exception as e:
print(f"❌ Gradio界面测试失败: {e}")
def main():
"""主测试函数"""
print("=" * 60)
print("🧪 Genie TTS 模块化重构 - 功能测试")
print("=" * 60)
test_imports()
test_configuration()
test_tts_interface()
test_ui_functions()
test_gradio_interface()
print("\n" + "=" * 60)
print("✨ 模块化重构测试完成!")
print("🎉 代码已成功拆分为独立、可维护的模块")
print("=" * 60)
if __name__ == "__main__":
main() |