# -*- coding: UTF-8 -*- """ @Project :pytest_src @File :test_case.py @Author :haojiang @Date :2022/9/23 10:09 """ import logging import allure import pytest from Base.MatrixParser import MatrixParser from Base.SignalInitTableCheck import MatrixSignalInitValueCheck, SignalValueCheck, SignalInitValueTableCheck, \ SignalAttrType from Base.Utils import get_arxml_path # MATRIX_PATH = r'D:\01_Work\02_WP\EC32\branch\src\MatrixAssistant_V2.0\20220908_gx2_EC32_计划外_GW' MATRIX_PATH = r'D:\01_Work\02_WP\EC32\branch\src\MatrixAssistant_V2.0\20221013_gx2_EC32_PPV_GW' arxml_path = get_arxml_path(MATRIX_PATH) print(arxml_path) mp = MatrixParser(arxml_path) # r'E:\Project\EP39\EP39_GW04_V1.1a_20220628_Integation\InputFiles\MA_20220607_qy1_EP39EV_simu_GWC-arxmal-V01.1.arxml') mc = MatrixSignalInitValueCheck() all_data = mc.get_signal_attr_data_by_dataframe(mp.all_dataframe['ISignal']) def test_01_csv_check(): ''' CSV 初值表 信号有效性检查,包括初值缺失、格式及值是否超出范围。 :return: ''' sc = SignalInitValueTableCheck(MATRIX_PATH) data = sc.get_signal_init_value_table() ret = True for row in data: # sc.check_row(row) scb = SignalValueCheck(row) ret_status, ret_code = scb.check_attribute() if not ret_status: ret = False assert True == ret # @pytest.mark.parametrize("signal_attr", all_data) # def test_02_matrix_signal_check(signal_attr: dict): # white_list = ['_NM_', 'NKI', 'NWI'] # sc = SignalValueCheck(signal_attr) # ret, ret_code = sc.check_attribute() # # if ret_code == 1: # for word in white_list: # if word in signal_attr[SignalAttrType.SIGNAL_NAME.name]: # ret = True # # assert True == ret def test_02_matrix_signal_check(): ''' 通信矩阵 系统信号有效性检查,包括初值缺失、格式及值是否超出范围。 当初值缺失时,需进一步信号名是否在白名单内。当前NM-PDU中包含的信号,处于白名单。 :return: ''' ret = True white_list = ['_NM_', 'NKI', 'NWI'] for row in all_data: # sc.check_row(row) scb = SignalValueCheck(row) ret_status, ret_code = scb.check_attribute() if ret_code == 1: for word in white_list: if word in row[SignalAttrType.SIGNAL_NAME.name]: ret_status = True if not ret_status: ret = False assert True == ret def test_03_matrix_dcm_pdu_name_check(): ''' DCM N-PDU 命名检查,主要是检查命名中是否有Phys,曾出现少了s。 :return: ''' dcm_pdu_df = mp.all_dataframe['Dcm_IPdu'] criterion = dcm_pdu_df['PDU Name'].str.contains('Phys') | dcm_pdu_df['PDU Name'].str.contains('Fun') ret = criterion.all() if not ret: logging.error('DCM PDU Name should include Phys!') logging.error(dcm_pdu_df['PDU Name']) assert True == ret def test_04_matrix_dcm_pdu_length_check(): ''' DCM N-PDU 长度检查,主要是检查是否为[4095, 7]。 :return: ''' dcm_pdu_df = mp.all_dataframe['Dcm_IPdu'] criterion = dcm_pdu_df['PDU Length'].isin(['7', '4095']) # print(criterion) ret = criterion.all() if not ret: logging.error('DCM PDU Length must is 7 or 4095!') logging.error(dcm_pdu_df[['PDU Name', 'PDU Length']]) assert True == ret def test_05_matrix_contained_pdu_header_id_check(): ''' contained pdu header id检查 :return: ''' ipdu_df = mp.all_dataframe['IPdu'] criterion = ipdu_df['Contained PDU ID'] == '0' ret = ~(criterion.all()) if not ret: logging.error('Contained Pdu id must not be 0!') logging.error(ipdu_df[['PDU Name', 'Contained PDU ID']]) assert True == ret