#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 简单语法测试 验证修复后的代码语法是否正确 """ import ast import os def test_file_syntax(file_path): """测试文件语法""" try: with open(file_path, 'r', encoding='utf-8') as f: content = f.read() # 解析AST ast.parse(content) return True, None except SyntaxError as e: return False, f"语法错误: {e}" except Exception as e: return False, f"其他错误: {e}" def main(): """主测试函数""" print("🚀 开始语法测试") print("=" * 60) # 测试修复的文件 test_files = [ "src/app/services/auth_service.py", "src/views/auth_view.py", "src/views/tag_view.py", "src/views/system_view.py", "src/app/utils/auth_decorator.py", "src/app/services/jwt_token.py" ] all_passed = True for file_path in test_files: if os.path.exists(file_path): success, error = test_file_syntax(file_path) if success: print(f"✅ {file_path}: 语法正确") else: print(f"❌ {file_path}: {error}") all_passed = False else: print(f"⚠️ {file_path}: 文件不存在") print("\n" + "=" * 60) if all_passed: print("🎉 所有文件语法测试通过!") print("\n📋 修复总结:") print("✅ AuthService.get_current_user() 现在返回 (user, new_token)") print("✅ AuthService.get_current_user_only() 提供向后兼容") print("✅ auth_view.py 正确处理元组返回值") print("✅ tag_view.py 使用向后兼容方法") print("✅ 所有相关文件语法正确") else: print("❌ 部分文件存在语法错误") if __name__ == "__main__": main()