161 lines
4.7 KiB
Python
161 lines
4.7 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
工单查询增强功能测试脚本
|
|
"""
|
|
import json
|
|
from pathlib import Path
|
|
|
|
def test_config_loading():
|
|
"""测试配置加载功能"""
|
|
print("=" * 60)
|
|
print("测试1: 配置加载")
|
|
print("=" * 60)
|
|
|
|
from work_order_query import load_db_config, DEFAULT_CONFIG
|
|
|
|
config = load_db_config()
|
|
|
|
# 验证target_process_name字段存在
|
|
assert 'target_process_name' in config, "配置中缺少 target_process_name 字段"
|
|
print(f"✓ target_process_name 字段存在: {config['target_process_name']}")
|
|
|
|
# 验证默认值
|
|
if config['target_process_name'] == '泵空跑合':
|
|
print(f"✓ 默认值正确: {config['target_process_name']}")
|
|
else:
|
|
print(f"✓ 使用配置文件中的值: {config['target_process_name']}")
|
|
|
|
print()
|
|
|
|
def test_debug_mode():
|
|
"""测试调试模式"""
|
|
print("=" * 60)
|
|
print("测试2: 调试模式")
|
|
print("=" * 60)
|
|
|
|
from work_order_query import query_work_order, WORK_ORDER_DB_CONFIG
|
|
|
|
# 临时启用debug模式
|
|
original_debug = WORK_ORDER_DB_CONFIG.get('debug_mode', False)
|
|
WORK_ORDER_DB_CONFIG['debug_mode'] = True
|
|
|
|
try:
|
|
result = query_work_order("TEST-001")
|
|
|
|
assert result is not None, "调试模式应该返回数据"
|
|
print(f"✓ 调试模式返回数据")
|
|
|
|
# 验证所有必需字段
|
|
required_fields = ['work_order_no', 'process_no', 'process_name', 'part_no', 'executor']
|
|
for field in required_fields:
|
|
assert field in result, f"缺少字段: {field}"
|
|
print(f"✓ 字段存在: {field} = {result[field]}")
|
|
|
|
finally:
|
|
# 恢复原始debug模式设置
|
|
WORK_ORDER_DB_CONFIG['debug_mode'] = original_debug
|
|
|
|
print()
|
|
|
|
def test_config_file_structure():
|
|
"""测试配置文件结构"""
|
|
print("=" * 60)
|
|
print("测试3: 配置文件结构")
|
|
print("=" * 60)
|
|
|
|
config_file = Path(__file__).parent / 'work_order_db_config.json'
|
|
|
|
if config_file.exists():
|
|
with open(config_file, 'r', encoding='utf-8') as f:
|
|
config = json.load(f)
|
|
|
|
# 验证target_process_name字段
|
|
if 'target_process_name' in config:
|
|
print(f"✓ 配置文件包含 target_process_name: {config['target_process_name']}")
|
|
else:
|
|
print("⚠ 配置文件缺少 target_process_name 字段(将使用默认值)")
|
|
|
|
# 显示配置文件内容
|
|
print("\n配置文件内容:")
|
|
print(json.dumps(config, ensure_ascii=False, indent=2))
|
|
else:
|
|
print("⚠ 配置文件不存在,将在首次运行时创建")
|
|
|
|
print()
|
|
|
|
def test_database_schema():
|
|
"""测试数据库schema"""
|
|
print("=" * 60)
|
|
print("测试4: 数据库Schema")
|
|
print("=" * 60)
|
|
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
db_path = Path(__file__).parent / 'experiments.db'
|
|
|
|
if db_path.exists():
|
|
conn = sqlite3.connect(str(db_path))
|
|
cursor = conn.cursor()
|
|
|
|
# 获取表结构
|
|
cursor.execute("PRAGMA table_info(experiments)")
|
|
columns = cursor.fetchall()
|
|
|
|
column_names = [col[1] for col in columns]
|
|
|
|
# 验证新字段
|
|
if 'process_name' in column_names:
|
|
print("✓ process_name 字段存在")
|
|
else:
|
|
print("⚠ process_name 字段不存在(将在程序启动时自动添加)")
|
|
|
|
if 'part_no' in column_names:
|
|
print("✓ part_no 字段存在")
|
|
else:
|
|
print("⚠ part_no 字段不存在(将在程序启动时自动添加)")
|
|
|
|
print("\n数据库表结构:")
|
|
for col in columns:
|
|
print(f" {col[1]}: {col[2]}")
|
|
|
|
conn.close()
|
|
else:
|
|
print("⚠ 数据库文件不存在,将在程序首次运行时创建")
|
|
|
|
print()
|
|
|
|
def main():
|
|
"""运行所有测试"""
|
|
print("\n" + "=" * 60)
|
|
print("工单查询增强功能测试")
|
|
print("=" * 60 + "\n")
|
|
|
|
try:
|
|
test_config_loading()
|
|
test_debug_mode()
|
|
test_config_file_structure()
|
|
test_database_schema()
|
|
|
|
print("=" * 60)
|
|
print("✓ 所有测试通过!")
|
|
print("=" * 60)
|
|
print("\n下一步:")
|
|
print("1. 启动程序: python main.py")
|
|
print("2. 点击「开始工单」按钮")
|
|
print("3. 输入工单号进行测试")
|
|
print("4. 查看实验历史列表中的新列(工序名称、零件号)")
|
|
print()
|
|
|
|
except Exception as e:
|
|
print(f"\n✗ 测试失败: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
return 1
|
|
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
exit(main())
|