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

73 lines
3.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 python3
# -*- coding: utf-8 -*-
"""
测试控制台输出效果 - 验证中文和表情文字显示
"""
import sys
import os
import time
# 设置Windows控制台支持UTF-8编码
if os.name == 'nt': # Windows系统
# 设置控制台编码为UTF-8
os.system('chcp 65001 >nul 2>&1')
# 重新配置stdout和stderr以支持UTF-8禁用缓冲
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace', line_buffering=True)
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace', line_buffering=True)
# 确保输出立即刷新
sys.stdout.reconfigure(encoding='utf-8', errors='replace', line_buffering=True)
sys.stderr.reconfigure(encoding='utf-8', errors='replace', line_buffering=True)
def test_console_output():
"""测试控制台输出效果"""
print("\n" + "="*60, flush=True)
print("🧪 控制台输出测试开始", flush=True)
print("="*60, flush=True)
# 测试中文输出
print("📝 测试中文输出:", flush=True)
print(" ✅ 简体中文: 药店销售预测系统", flush=True)
print(" ✅ 繁体中文: 藥店銷售預測系統", flush=True)
print(" ✅ 混合文本: Product P001 - 阿司匹林片", flush=True)
# 测试表情符号
print("\n🎨 测试表情符号输出:", flush=True)
print(" 🚀 启动 📊 数据 🤖 模型 💾 保存", flush=True)
print(" ⚙️ 配置 🏷️ 版本 📈 训练 ✅ 完成", flush=True)
print(" 📡 通信 🖥️ 设备 📁 文件 ⏱️ 时间", flush=True)
# 测试训练进度模拟
print("\n🏃 模拟训练进度输出:", flush=True)
for epoch in range(1, 4):
loss = 0.1234 - epoch * 0.01
print(f" 📊 Epoch {epoch}/3, 训练损失: {loss:.4f}, 测试损失: {loss+0.01:.4f}", flush=True)
time.sleep(0.5) # 模拟训练时间
# 测试任务状态输出
print("\n📋 模拟任务状态输出:", flush=True)
task_id = "test-12345"
print(f" 🚀 训练任务开始: {task_id}", flush=True)
print(f" 📋 任务详情: 训练 TRANSFORMER 模型 - 药品 P001", flush=True)
print(f" ⚙️ 配置参数: 共 50 个轮次", flush=True)
print(f" 🏷️ 版本信息: 版本号 v1.0, 模型标识: P001", flush=True)
print(f" 📊 进度管理器已初始化", flush=True)
print(f" 🏃 开始调用训练器 - 模式: product, 模型: transformer", flush=True)
print(f" 🤖 调用 TRANSFORMER 训练器 - 产品: P001", flush=True)
# 测试训练完成输出
print("\n✅ 模拟训练完成输出:", flush=True)
print(f" 📈 训练完成! 结果类型: <class 'dict'>", flush=True)
print(f" 📊 训练指标: {{'mse': 0.0123, 'rmse': 0.1107, 'r2': 0.95}}", flush=True)
print(f" 💾 模型保存路径: saved_models/transformer/P001_v1.0.pth", flush=True)
print(f" ✔️ 任务状态更新: 已完成, 版本: v1.0", flush=True)
print(f" 📡 发送WebSocket完成消息", flush=True)
print("\n" + "="*60, flush=True)
print("🎉 控制台输出测试完成! 如果能看到上述所有中文和表情符号,说明编码配置正确。", flush=True)
print("="*60, flush=True)
if __name__ == "__main__":
test_console_output()