CfgCheckBase.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # -*- coding: UTF-8 -*-
  2. """
  3. @Project :pytest_src
  4. @File :CfgCheckBase.py
  5. @Author :haojiang
  6. @Date :2022/9/23 8:52
  7. """
  8. from lxml import etree
  9. from Base.Arxml import Arxml
  10. import logging
  11. class CfgCheckBase:
  12. def __init__(self):
  13. pass
  14. def parameter_match(self, element: etree.Element,
  15. param_name: str,
  16. param_expect_value: str,
  17. is_multi_container:bool = False) -> bool:
  18. '''
  19. :param element: 待查询container
  20. :param param_name: 配置项值
  21. :param param_expect_value: 期望的配置值
  22. :param is_multi_container: 是否匹配多个相同的配置项
  23. :return: 是否与期望值匹配
  24. '''
  25. param_definition_ref_containers = Arxml.get_all_match_element(element,
  26. './/DEFINITION-REF',
  27. param_name,
  28. xpath_rule='CONTAINS')
  29. compare_result = True
  30. if len(param_definition_ref_containers) != 0:
  31. for def_elem in param_definition_ref_containers:
  32. value_elem = Arxml.get_brother_element(def_elem, './VALUE')
  33. if value_elem != None:
  34. value = Arxml.get_container_text(value_elem)
  35. else:
  36. logging.error(f"Check Param {param_name} not find a valid element!")
  37. value = None
  38. compare_result = param_expect_value == value
  39. if not compare_result:
  40. compare_result = False
  41. logging.error(f"Check Param {param_name} not match! Expect Value {param_expect_value} != {value}")
  42. return compare_result
  43. def get_dismatch_value_element_name(self, value_element: etree.Element) -> str:
  44. return ''
  45. def main():
  46. project_path = r'D:\01_Work\02_WP\EP39_EREV\branch\src\Config\ECUC\EH32_GW04_Dem_ecuc.arxml'
  47. # project_path = r'D:\01_Work\02_WP\EP39_EREV\branch\src\Config\ECUC\EH32_GW04_CanTp_ecuc.arxml'
  48. arxml = Arxml(project_path)
  49. root = arxml.root
  50. cfg_check = CfgCheckBase()
  51. # cfg_check.parameter_match(root, 'CanTpChannelMode', 'CANTP_MODE_FULL_DUPLEX', True)
  52. # cfg_check.parameter_match(root, 'DemClearDTCBehavior', 'DEM_CLRRESP_VOLATILE', True)
  53. cfg_check.parameter_match(root, 'DemMaxNumberEventEntryPrimary', '41')
  54. if __name__ == '__main__':
  55. main()