test_case.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # -*- coding: UTF-8 -*-
  2. """
  3. @Project :pytest_src
  4. @File :test_case.py
  5. @Author :haojiang
  6. @Date :2022/9/23 10:09
  7. """
  8. import allure
  9. import pytest
  10. from Base.ModuleCfgCheck import ModuleCfgCheck, check_module_param_check
  11. from Cfg import HARDWARE_TYPE, PROJECT_TYPE, PROJECT
  12. from Data.DataAccess import ItemType, get_xlsx_data_by_filter, HardwareType, ProjectType
  13. from Base.Arxml import Arxml
  14. from Base.BaseContainer import EcucContainerValue
  15. # HARDWARE_TYPE = HardwareType.GW04
  16. # PROJECT_TYPE = ProjectType.AS33
  17. # PROJECT = r'D:\01_Work\02_WP\EC32\branch\src\Config\ECUC'
  18. # PROJECT = r'D:\01_Work\02_WP\EP39_EV\branch\src\Config\ECUC'
  19. @allure.feature('Fix Value Parameter Check')
  20. @pytest.mark.parametrize("module_name, param_name, expect_value", get_xlsx_data_by_filter(HARDWARE_TYPE, PROJECT_TYPE, ItemType.FIXED_VALUE))
  21. def test_fix_value_case(module_name, param_name, expect_value):
  22. '''
  23. 该用例适用于 对某一配置项值进行检查,可能有多个container 都具有该配置项,但所有配置项的值都相同,为一固定值。
  24. 当有一个值与预期值不匹配时,将报错。
  25. :param module_name:
  26. :param param_name:
  27. :param expect_value:
  28. :return:
  29. '''
  30. item = (param_name, expect_value)
  31. res = check_module_param_check(PROJECT, module_name, item)
  32. assert True == res
  33. @allure.feature('Custom Pattern Parameter Check')
  34. @pytest.mark.parametrize("module_name, search_pattern, param_name, expect_value", get_xlsx_data_by_filter(HARDWARE_TYPE, PROJECT_TYPE, ItemType.CUSTOM_PATTERN))
  35. def test_custom_pattern_case(module_name, search_pattern, param_name, expect_value):
  36. '''
  37. 该用例适用于测试 通过某种模式规则,定位到唯一的container, 该container包含的指定配置项,是否与期望值相同。
  38. 例如,可能多个container 都具有该配置项,但对于目标container, 可能和其他container 配置值不同。
  39. :param module_name:
  40. :param search_pattern:
  41. :param param_name:
  42. :param expect_value:
  43. :return:
  44. '''
  45. item = (param_name, expect_value)
  46. res = check_module_param_check(PROJECT, module_name, item, search_pattern)
  47. assert True == res
  48. # @allure.feature('case03')
  49. # @pytest.mark.parametrize("module_name, search_pattern, param_name, expect_value", get_xlsx_data_by_filter(PROJECT_TYPE, ItemType.DEPENDENCY_PATTERN))
  50. # def test_03_case(module_name, search_pattern, param_name, expect_value):
  51. # # 该测试用例,用于目标container 需要使用 依赖关系才能确定确定的场景。
  52. #
  53. # print(module_name, search_pattern, param_name, expect_value)
  54. # assert True == False
  55. # pass
  56. @allure.feature('CanIfRxPduDlcCheck Check')
  57. @allure.title('CanIfRxPduDlcCheck 检查')
  58. def test_canif_dlc_check_case():
  59. '''
  60. 该用例用于 CanIf 模块 CanIfRxPduCfg 的CanIfRxPduDlcCheck 检查。
  61. :return:
  62. '''
  63. mcc = ModuleCfgCheck('CanIf', PROJECT)
  64. canif_init_cfg = Arxml.get_first_match_element(mcc.arxml_root, './/SHORT-NAME', 'CanIfInitCfg', 'TEXT_EQ')
  65. ecuc_containers = Arxml.get_all_match_element(Arxml.get_parent_element(canif_init_cfg), './/ECUC-CONTAINER-VALUE')
  66. for ecuc in ecuc_containers:
  67. ecuc_con = EcucContainerValue(ecuc)
  68. ecuc_con_attr = ecuc_con.container_attr
  69. ecuc_type = Arxml.get_split_end_value(ecuc_con_attr['container_definition_ref'][-1])
  70. if ecuc_type == 'CanIfRxPduCfg':
  71. CanIfRxPduDlc = ecuc_con_attr['parameter_values']['CanIfRxPduDlc'][-1]
  72. CanIfRxPduDlcCheck = ecuc_con_attr['parameter_values']['CanIfRxPduDlcCheck'][-1]
  73. # print(CanIfRxPduDlc, CanIfRxPduDlcCheck)
  74. if (CanIfRxPduDlc == '64' and 'true' == CanIfRxPduDlcCheck) or \
  75. (CanIfRxPduDlc != '64' and 'false' == CanIfRxPduDlcCheck):
  76. print(f"DLC Check ERROR! {ecuc_con_attr['short_name']}, dlc is {CanIfRxPduDlc} , actual dlccheck is {CanIfRxPduDlcCheck}")
  77. assert True == False
  78. @allure.feature('CanIfBufferSize Check')
  79. @allure.title('tx buffer 配置检查')
  80. def test_canif_buffersize_check_case():
  81. '''
  82. 该用例用于 CanIf 模块 CanIfBufferCfg CanIfBufferSize CanIfTxBufferHandlingType检查。
  83. :return:
  84. '''
  85. mcc = ModuleCfgCheck('CanIf', PROJECT)
  86. canif_init_cfg = Arxml.get_first_match_element(mcc.arxml_root, './/SHORT-NAME', 'CanIfInitCfg', 'TEXT_EQ')
  87. ecuc_containers = Arxml.get_all_match_element(Arxml.get_parent_element(canif_init_cfg), './/ECUC-CONTAINER-VALUE')
  88. for ecuc in ecuc_containers:
  89. ecuc_con = EcucContainerValue(ecuc)
  90. ecuc_con_attr = ecuc_con.container_attr
  91. ecuc_type = Arxml.get_split_end_value(ecuc_con_attr['container_definition_ref'][-1])
  92. if ecuc_type == 'CanIfBufferCfg':
  93. CanIfTxBufferHandlingType = ecuc_con_attr['parameter_values']['CanIfTxBufferHandlingType'][-1]
  94. CanIfBufferSize = ecuc_con_attr['parameter_values']['CanIfBufferSize'][-1]
  95. CanIfTxBufferMappedTxPdus = ecuc_con_attr['parameter_values']['CanIfTxBufferMappedTxPdus'][-1]
  96. print(f"{ecuc_con_attr['short_name']}, CanIfTxBufferHandlingType={CanIfTxBufferHandlingType}")
  97. if ('CanIfBufferCfg' not in ecuc_con_attr['short_name'] and
  98. int(CanIfTxBufferMappedTxPdus) > int(CanIfBufferSize)):
  99. print(f"CanIfBufferSize Check ERROR! {ecuc_con_attr['short_name']}, CanIfBufferSize={CanIfBufferSize}, CanIfTxBufferMappedTxPdus={CanIfTxBufferMappedTxPdus}")
  100. assert True == False