test_case.py 5.3 KB

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