test_case.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 logging
  9. import allure
  10. import pytest
  11. from Base.MatrixParser import MatrixParser
  12. from Base.SignalInitTableCheck import MatrixSignalInitValueCheck, SignalValueCheck, SignalInitValueTableCheck, \
  13. SignalAttrType
  14. from Base.Utils import get_arxml_path
  15. # MATRIX_PATH = r'D:\01_Work\02_WP\EC32\branch\src\MatrixAssistant_V2.0\20220908_gx2_EC32_计划外_GW'
  16. MATRIX_PATH = r'D:\01_Work\02_WP\EC32\branch\src\MatrixAssistant_V2.0\20221013_gx2_EC32_PPV_GW'
  17. arxml_path = get_arxml_path(MATRIX_PATH)
  18. print(arxml_path)
  19. mp = MatrixParser(arxml_path)
  20. # r'E:\Project\EP39\EP39_GW04_V1.1a_20220628_Integation\InputFiles\MA_20220607_qy1_EP39EV_simu_GWC-arxmal-V01.1.arxml')
  21. mc = MatrixSignalInitValueCheck()
  22. all_data = mc.get_signal_attr_data_by_dataframe(mp.all_dataframe['ISignal'])
  23. def test_01_csv_check():
  24. '''
  25. CSV 初值表 信号有效性检查,包括初值缺失、格式及值是否超出范围。
  26. :return:
  27. '''
  28. sc = SignalInitValueTableCheck(MATRIX_PATH)
  29. data = sc.get_signal_init_value_table()
  30. ret = True
  31. for row in data:
  32. # sc.check_row(row)
  33. scb = SignalValueCheck(row)
  34. ret_status, ret_code = scb.check_attribute()
  35. if not ret_status:
  36. ret = False
  37. assert True == ret
  38. # @pytest.mark.parametrize("signal_attr", all_data)
  39. # def test_02_matrix_signal_check(signal_attr: dict):
  40. # white_list = ['_NM_', 'NKI', 'NWI']
  41. # sc = SignalValueCheck(signal_attr)
  42. # ret, ret_code = sc.check_attribute()
  43. #
  44. # if ret_code == 1:
  45. # for word in white_list:
  46. # if word in signal_attr[SignalAttrType.SIGNAL_NAME.name]:
  47. # ret = True
  48. #
  49. # assert True == ret
  50. def test_02_matrix_signal_check():
  51. '''
  52. 通信矩阵 系统信号有效性检查,包括初值缺失、格式及值是否超出范围。
  53. 当初值缺失时,需进一步信号名是否在白名单内。当前NM-PDU中包含的信号,处于白名单。
  54. :return:
  55. '''
  56. ret = True
  57. white_list = ['_NM_', 'NKI', 'NWI']
  58. for row in all_data:
  59. # sc.check_row(row)
  60. scb = SignalValueCheck(row)
  61. ret_status, ret_code = scb.check_attribute()
  62. if ret_code == 1:
  63. for word in white_list:
  64. if word in row[SignalAttrType.SIGNAL_NAME.name]:
  65. ret_status = True
  66. if not ret_status:
  67. ret = False
  68. assert True == ret
  69. def test_03_matrix_dcm_pdu_name_check():
  70. '''
  71. DCM N-PDU 命名检查,主要是检查命名中是否有Phys,曾出现少了s。
  72. :return:
  73. '''
  74. dcm_pdu_df = mp.all_dataframe['Dcm_IPdu']
  75. criterion = dcm_pdu_df['PDU Name'].str.contains('Phys') | dcm_pdu_df['PDU Name'].str.contains('Fun')
  76. ret = criterion.all()
  77. if not ret:
  78. logging.error('DCM PDU Name should include Phys!')
  79. logging.error(dcm_pdu_df['PDU Name'])
  80. assert True == ret
  81. def test_04_matrix_dcm_pdu_length_check():
  82. '''
  83. DCM N-PDU 长度检查,主要是检查是否为[4095, 7]。
  84. :return:
  85. '''
  86. dcm_pdu_df = mp.all_dataframe['Dcm_IPdu']
  87. criterion = dcm_pdu_df['PDU Length'].isin(['7', '4095'])
  88. # print(criterion)
  89. ret = criterion.all()
  90. if not ret:
  91. logging.error('DCM PDU Length must is 7 or 4095!')
  92. logging.error(dcm_pdu_df[['PDU Name', 'PDU Length']])
  93. assert True == ret
  94. def test_05_matrix_contained_pdu_header_id_check():
  95. '''
  96. contained pdu header id检查
  97. :return:
  98. '''
  99. ipdu_df = mp.all_dataframe['IPdu']
  100. criterion = ipdu_df['Contained PDU ID'] == '0'
  101. ret = ~(criterion.all())
  102. if not ret:
  103. logging.error('Contained Pdu id must not be 0!')
  104. logging.error(ipdu_df[['PDU Name', 'Contained PDU ID']])
  105. assert True == ret