# -*- coding: UTF-8 -*- """ @Project :pytest_src @File :test_case.py @Author :haojiang @Date :2022/9/23 10:09 """ import allure import pytest from Base.ModuleCfgCheck import ModuleCfgCheck, check_module_param_check from Data.DataAccess import ItemType, get_xlsx_data_by_filter, ProjectType from Base.Arxml import Arxml from Base.BaseContainer import EcucContainerValue PROJECT_TYPE = ProjectType.GW04 PROJECT = r'D:\01_Work\02_WP\AS33\branch\src_v6_1\Config\ECUC' # PROJECT = r'D:\01_Work\02_WP\EP39_EV\branch\src\Config\ECUC' @allure.feature('Fix Value Parameter Check') @pytest.mark.parametrize("module_name, param_name, expect_value", get_xlsx_data_by_filter(PROJECT_TYPE, ItemType.FIXED_VALUE)) def test_fix_value_case(module_name, param_name, expect_value): ''' 该用例适用于 对某一配置项值进行检查,可能有多个container 都具有该配置项,但所有配置项的值都相同,为一固定值。 当有一个值与预期值不匹配时,将报错。 :param module_name: :param param_name: :param expect_value: :return: ''' item = (param_name, expect_value) res = check_module_param_check(PROJECT, module_name, item) assert True == res @allure.feature('Custom Pattern Parameter Check') @pytest.mark.parametrize("module_name, search_pattern, param_name, expect_value", get_xlsx_data_by_filter(PROJECT_TYPE, ItemType.CUSTOM_PATTERN)) def test_custom_pattern_case(module_name, search_pattern, param_name, expect_value): ''' 该用例适用于测试 通过某种模式规则,定位到唯一的container, 该container包含的指定配置项,是否与期望值相同。 例如,可能多个container 都具有该配置项,但对于目标container, 可能和其他container 配置值不同。 :param module_name: :param search_pattern: :param param_name: :param expect_value: :return: ''' item = (param_name, expect_value) res = check_module_param_check(PROJECT, module_name, item, search_pattern) assert True == res # @allure.feature('case03') # @pytest.mark.parametrize("module_name, search_pattern, param_name, expect_value", get_xlsx_data_by_filter(PROJECT_TYPE, ItemType.DEPENDENCY_PATTERN)) # def test_03_case(module_name, search_pattern, param_name, expect_value): # # 该测试用例,用于目标container 需要使用 依赖关系才能确定确定的场景。 # # print(module_name, search_pattern, param_name, expect_value) # assert True == False # pass @allure.feature('CanIfRxPduDlcCheck Check') @allure.title('CanIfRxPduDlcCheck 检查') def test_canif_dlc_check_case(): ''' 该用例用于 CanIf 模块 CanIfRxPduCfg 的CanIfRxPduDlcCheck 检查。 :return: ''' mcc = ModuleCfgCheck('CanIf', PROJECT) canif_init_cfg = Arxml.get_first_match_element(mcc.arxml_root, './/SHORT-NAME', 'CanIfInitCfg', 'TEXT_EQ') ecuc_containers = Arxml.get_all_match_element(Arxml.get_parent_element(canif_init_cfg), './/ECUC-CONTAINER-VALUE') for ecuc in ecuc_containers: ecuc_con = EcucContainerValue(ecuc) ecuc_con_attr = ecuc_con.container_attr ecuc_type = Arxml.get_split_end_value(ecuc_con_attr['container_definition_ref'][-1]) if ecuc_type == 'CanIfRxPduCfg': CanIfRxPduDlc = ecuc_con_attr['parameter_values']['CanIfRxPduDlc'][-1] CanIfRxPduDlcCheck = ecuc_con_attr['parameter_values']['CanIfRxPduDlcCheck'][-1] # print(CanIfRxPduDlc, CanIfRxPduDlcCheck) if (CanIfRxPduDlc == '64' and 'true' == CanIfRxPduDlcCheck) or \ (CanIfRxPduDlc != '64' and 'false' == CanIfRxPduDlcCheck): print(f"DLC Check ERROR! {ecuc_con_attr['short_name']}, dlc is {CanIfRxPduDlc} , actual dlccheck is {CanIfRxPduDlcCheck}") assert True == False @allure.feature('CanIfBufferSize Check') @allure.title('tx buffer 配置检查') def test_canif_buffersize_check_case(): ''' 该用例用于 CanIf 模块 CanIfBufferCfg CanIfBufferSize CanIfTxBufferHandlingType检查。 :return: ''' mcc = ModuleCfgCheck('CanIf', PROJECT) canif_init_cfg = Arxml.get_first_match_element(mcc.arxml_root, './/SHORT-NAME', 'CanIfInitCfg', 'TEXT_EQ') ecuc_containers = Arxml.get_all_match_element(Arxml.get_parent_element(canif_init_cfg), './/ECUC-CONTAINER-VALUE') for ecuc in ecuc_containers: ecuc_con = EcucContainerValue(ecuc) ecuc_con_attr = ecuc_con.container_attr ecuc_type = Arxml.get_split_end_value(ecuc_con_attr['container_definition_ref'][-1]) if ecuc_type == 'CanIfBufferCfg': CanIfTxBufferHandlingType = ecuc_con_attr['parameter_values']['CanIfTxBufferHandlingType'][-1] CanIfBufferSize = ecuc_con_attr['parameter_values']['CanIfBufferSize'][-1] CanIfTxBufferMappedTxPdus = ecuc_con_attr['parameter_values']['CanIfTxBufferMappedTxPdus'][-1] print(f"{ecuc_con_attr['short_name']}, CanIfTxBufferHandlingType={CanIfTxBufferHandlingType}") if ('CanIfBufferCfg' not in ecuc_con_attr['short_name'] and int(CanIfTxBufferMappedTxPdus) > int(CanIfBufferSize)): print(f"CanIfBufferSize Check ERROR! {ecuc_con_attr['short_name']}, CanIfBufferSize={CanIfBufferSize}, CanIfTxBufferMappedTxPdus={CanIfTxBufferMappedTxPdus}") assert True == False