pfcfuse/test_shell.py
whaifree f95b13b8aa 新增测试脚本和日志记录功能
- 添加 test_shell.py脚本,实现自动测试和日志记录功能
- 新增 deployment.xml 和 iml 文件,配置项目部署和模块信息
- 添加 log_20241008_success.log 和 status.md 文件,记录测试结果和状态
- 更新 test_IVF.py,修改测试模型和输出路径
2024-10-09 11:52:46 +08:00

42 lines
1.4 KiB
Python

import os
import subprocess
import datetime
import sys
# 定义命令
command = "/home/star/anaconda3/envs/pfcfuse/bin/python /home/star/whaiDir/PFCFuse/test_IVF.py"
# 获取当前时间并格式化为文件名
current_time = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
output_file = f"/home/star/whaiDir/PFCFuse/logs/ans_log_{current_time}.log"
try:
# 打开文件用于写入
with open(output_file, 'w') as log_file:
# 运行命令
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True)
# 循环读取输出
for line in process.stdout:
# 同时打印到控制台和写入文件
print(line.strip())
log_file.write(line)
log_file.flush() # 确保立即写入文件
# 等待命令完成
process.wait()
# 检查返回码
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, command)
# 如果命令成功执行,则打印确认信息
print(f"Command executed successfully. Output has been written to {output_file}")
except subprocess.CalledProcessError as e:
# 如果命令执行失败,则删除文件并打印错误信息
if os.path.exists(output_file):
os.remove(output_file)
print(f"Command failed with return code {e.returncode}. No log file was created.")