50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
简单的语法测试脚本,检查evaluate_model.py是否有语法错误
|
||
"""
|
||
import sys
|
||
import os
|
||
|
||
# 添加路径
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'model_training'))
|
||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'model_training_lstm'))
|
||
|
||
try:
|
||
print("Testing imports...")
|
||
|
||
# 测试基本导入
|
||
import torch
|
||
import numpy as np
|
||
import pandas as pd
|
||
from omegaconf import OmegaConf
|
||
import time
|
||
from tqdm import tqdm
|
||
import editdistance
|
||
import argparse
|
||
print("✓ Basic imports successful")
|
||
|
||
# 测试模型导入
|
||
from model_training.rnn_model import GRUDecoder
|
||
from model_training_lstm.rnn_model import LSTMDecoder
|
||
from model_training.evaluate_model_helpers import *
|
||
print("✓ Model imports successful")
|
||
|
||
# 测试是否能解析evaluate_model.py文件语法
|
||
import ast
|
||
eval_file = os.path.join(os.path.dirname(__file__), 'evaluate_model.py')
|
||
with open(eval_file, 'r') as f:
|
||
code = f.read()
|
||
|
||
# 解析语法
|
||
ast.parse(code)
|
||
print("✓ evaluate_model.py syntax is valid")
|
||
|
||
print("\nAll tests passed! The modified code should work correctly.")
|
||
|
||
except SyntaxError as e:
|
||
print(f"✗ Syntax error in evaluate_model.py: {e}")
|
||
print(f"Line {e.lineno}: {e.text}")
|
||
except ImportError as e:
|
||
print(f"✗ Import error: {e}")
|
||
except Exception as e:
|
||
print(f"✗ Other error: {e}") |