# -*- coding: UTF-8 -*- """ @Project :pytest_src @File :CfgCheckBase.py @Author :haojiang @Date :2022/9/23 8:52 """ from lxml import etree from Base.Arxml import Arxml import logging class CfgCheckBase: def __init__(self): pass def parameter_match(self, element: etree.Element, param_name: str, param_expect_value: str, is_multi_container:bool = False) -> bool: ''' :param element: 待查询container :param param_name: 配置项值 :param param_expect_value: 期望的配置值 :param is_multi_container: 是否匹配多个相同的配置项 :return: 是否与期望值匹配 ''' param_definition_ref_containers = Arxml.get_all_match_element(element, './/DEFINITION-REF', param_name, xpath_rule='CONTAINS') compare_result = True if len(param_definition_ref_containers) != 0: for def_elem in param_definition_ref_containers: value_elem = Arxml.get_brother_element(def_elem, './VALUE') if value_elem != None: value = Arxml.get_container_text(value_elem) else: logging.error(f"Check Param {param_name} not find a valid element!") value = None compare_result = param_expect_value == value if not compare_result: compare_result = False logging.error(f"Check Param {param_name} not match! Expect Value {param_expect_value} != {value}") return compare_result def get_dismatch_value_element_name(self, value_element: etree.Element) -> str: return '' def main(): project_path = r'D:\01_Work\02_WP\EP39_EREV\branch\src\Config\ECUC\EH32_GW04_Dem_ecuc.arxml' # project_path = r'D:\01_Work\02_WP\EP39_EREV\branch\src\Config\ECUC\EH32_GW04_CanTp_ecuc.arxml' arxml = Arxml(project_path) root = arxml.root cfg_check = CfgCheckBase() # cfg_check.parameter_match(root, 'CanTpChannelMode', 'CANTP_MODE_FULL_DUPLEX', True) # cfg_check.parameter_match(root, 'DemClearDTCBehavior', 'DEM_CLRRESP_VOLATILE', True) cfg_check.parameter_match(root, 'DemMaxNumberEventEntryPrimary', '41') if __name__ == '__main__': main()