From 75d42b7aaba3456209e9e16b081ae55b001f75d5 Mon Sep 17 00:00:00 2001 From: gongwenxin Date: Tue, 19 Aug 2025 17:09:11 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=9C=9F=E5=AE=9Ewell=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ddms_compliance_suite/test_orchestrator.py | 58 ++++++++--------- docs/Well_Data_Integration_Guide.md | 9 +-- test_orchestrator_init.py | 73 ++++++++++++++++++++++ 3 files changed, 105 insertions(+), 35 deletions(-) create mode 100644 test_orchestrator_init.py diff --git a/ddms_compliance_suite/test_orchestrator.py b/ddms_compliance_suite/test_orchestrator.py index 5a6081d..45f9390 100644 --- a/ddms_compliance_suite/test_orchestrator.py +++ b/ddms_compliance_suite/test_orchestrator.py @@ -534,6 +534,33 @@ class APITestOrchestrator: else: self.logger.info("No stages_dir provided, stage testing will be skipped.") + # 完成其他初始化 + self.output_dir_path = Path(output_dir) if output_dir else Path("./test_reports_orchestrator") + try: + self.output_dir_path.mkdir(parents=True, exist_ok=True) + self.logger.info(f"Orchestrator output directory set to: {self.output_dir_path.resolve()}") + except OSError as e: + self.logger.warning(f"Could not create orchestrator output directory {self.output_dir_path}: {e}. Falling back to current directory.") + self.output_dir_path = Path(".") + + self.schema_cache: Dict[str, Type[BaseModel]] = {} + self.model_name_counts: Dict[str, int] = defaultdict(int) + self.parser = InputParser() + self.json_resolver_cache: Dict[str, Any] = {} + self.json_validator = JSONSchemaValidator() + + # 将字符串类型的 strictness_level 转换为 TestSeverity 枚举成员 + self.strictness_level: Optional[TestSeverity] = None + if strictness_level and hasattr(TestSeverity, strictness_level): + self.strictness_level = TestSeverity[strictness_level] + logging.info(f"strictness_level: {self.strictness_level}") + elif strictness_level: + logging.warning(f"提供了无效的严格等级 '{strictness_level}'。将使用默认行为。有效值: {', '.join([e.name for e in TestSeverity])}") + + # 将这些属性的初始化移到此处,并设为None,避免在_execute_tests_from_parsed_spec之前被错误使用 + self.json_schema_validator: Optional[JSONSchemaValidator] = None + self.schema_provider: Optional[SchemaProvider] = None + def initialize_well_data(self) -> bool: """ 初始化井数据,在测试开始前获取真实的井和井筒数据 @@ -555,37 +582,6 @@ class APITestOrchestrator: self.logger.error(f"井数据初始化失败: {e}") return False - def _complete_initialization(self, output_dir: Optional[str], strictness_level: Optional[str]): - """完成初始化过程""" - self.output_dir_path = Path(output_dir) if output_dir else Path("./test_reports_orchestrator") - try: - self.output_dir_path.mkdir(parents=True, exist_ok=True) - self.logger.info(f"Orchestrator output directory set to: {self.output_dir_path.resolve()}") - except OSError as e: - self.logger.warning(f"Could not create orchestrator output directory {self.output_dir_path}: {e}. Falling back to current directory.") - self.output_dir_path = Path(".") - - self.schema_cache: Dict[str, Type[BaseModel]] = {} - self.model_name_counts: Dict[str, int] = defaultdict(int) - self.parser = InputParser() - self.json_resolver_cache: Dict[str, Any] = {} - self.json_validator = JSONSchemaValidator() - - # 将字符串类型的 strictness_level 转换为 TestSeverity 枚举成员 - self.strictness_level: Optional[TestSeverity] = None - if strictness_level and hasattr(TestSeverity, strictness_level): - self.strictness_level = TestSeverity[strictness_level] - logging.info(f"strictness_level: {self.strictness_level}") - elif strictness_level: - logging.warning(f"提供了无效的严格等级 '{strictness_level}'。将使用默认行为。有效值: {', '.join([e.name for e in TestSeverity])}") - - # 将这些属性的初始化移到此处,并设为None,避免在_execute_tests_from_parsed_spec之前被错误使用 - self.json_schema_validator: Optional[JSONSchemaValidator] = None - self.schema_provider: Optional[SchemaProvider] = None - - # 完成初始化 - self._complete_initialization(output_dir, strictness_level) - def get_api_call_details(self) -> List[APICallDetail]: """Returns the collected list of API call details.""" return self.global_api_call_details diff --git a/docs/Well_Data_Integration_Guide.md b/docs/Well_Data_Integration_Guide.md index e0644f8..3354bde 100644 --- a/docs/Well_Data_Integration_Guide.md +++ b/docs/Well_Data_Integration_Guide.md @@ -14,10 +14,11 @@ - **错误处理**: 当井数据获取失败时,自动回退到模拟数据 ### 支持的字段 -- `wellId` / `well_id` - 井ID -- `wellboreId` / `wellbore_id` - 井筒ID -- `wellCommonName` / `well_common_name` - 井通用名称 -- `wellboreCommonName` / `wellbore_common_name` - 井筒通用名称 +- `wellId` - 井ID(严格匹配字段名) +- `wellboreId` - 井筒ID(严格匹配字段名) +- `wellCommonName` - 井通用名称(严格匹配字段名) + +> **注意**: 字段名称严格按照DMS接口规范,不支持变体命名(如well_id、WELL_ID等) ## 🏗️ 架构设计 diff --git a/test_orchestrator_init.py b/test_orchestrator_init.py new file mode 100644 index 0000000..883c66e --- /dev/null +++ b/test_orchestrator_init.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 +""" +测试APITestOrchestrator初始化的脚本 +""" + +import sys +import logging +from ddms_compliance_suite.test_orchestrator import APITestOrchestrator + +def test_orchestrator_initialization(): + """测试APITestOrchestrator的初始化""" + + # 设置日志 + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') + logger = logging.getLogger(__name__) + + logger.info("开始测试APITestOrchestrator初始化...") + + try: + # 初始化编排器 + orchestrator = APITestOrchestrator( + base_url="https://www.dev.ideas.cnpc", + strictness_level="CRITICAL", + ignore_ssl=True, + enable_well_data=True + ) + + # 检查关键属性是否正确初始化 + logger.info("✅ APITestOrchestrator初始化成功") + + # 检查strictness_level属性 + if hasattr(orchestrator, 'strictness_level'): + logger.info(f"✅ strictness_level属性存在: {orchestrator.strictness_level}") + else: + logger.error("❌ strictness_level属性不存在") + return False + + # 检查井数据管理器 + if hasattr(orchestrator, 'well_data_manager'): + if orchestrator.well_data_manager: + logger.info("✅ 井数据管理器已初始化") + else: + logger.info("ℹ️ 井数据管理器未启用") + else: + logger.error("❌ well_data_manager属性不存在") + return False + + # 检查其他关键属性 + required_attrs = [ + 'base_url', 'api_caller', 'test_case_registry', + 'global_api_call_details', 'ignore_ssl', 'llm_config', + 'output_dir_path', 'schema_cache', 'parser' + ] + + for attr in required_attrs: + if hasattr(orchestrator, attr): + logger.info(f"✅ {attr}属性存在") + else: + logger.error(f"❌ {attr}属性不存在") + return False + + logger.info("🎉 所有属性检查通过") + return True + + except Exception as e: + logger.error(f"❌ APITestOrchestrator初始化失败: {e}") + import traceback + traceback.print_exc() + return False + +if __name__ == "__main__": + success = test_orchestrator_initialization() + sys.exit(0 if success else 1)