コード例 #1
0
 def test_lap_current(self):
     session = Session(session_uid="vettel2021")
     session.lap_number_current = 2
     session.lap_list = {
         2: {
             "sector_1_time_ms": 10002,
             "sector_2_time_ms": 20002,
             "sector_3_time_ms": 30002,
             "lap_number": 2,
             "car_race_position": 1,
             "pit_status": 1
         }
     }
     packet = get_packet_mock()
     packet.lapData = [
         MagicMock(currentLapNum=2,
                   currentLapTime=80,
                   sector1TimeInMS=10002,
                   sector2TimeInMS=20002,
                   pitStatus=2,
                   carPosition=4,
                   currentLapInvalid=0)
     ]
     session = LapPacket().process(packet, session)
     self.assertEqual(
         session.lap_list, {
             2: {
                 'sector_1_time_ms': 10002,
                 'sector_2_time_ms': 20002,
                 'sector_3_time_ms': 49996,
                 'lap_number': 2,
                 'car_race_position': 4,
                 'pit_status': 2,
                 'is_valid': True
             }
         })
     self.assertEqual(session.lap_number_current, 2)
     # invalid lap
     packet.lapData = [
         MagicMock(currentLapNum=2,
                   currentLapTime=80,
                   sector1TimeInMS=10002,
                   sector2TimeInMS=20002,
                   pitStatus=2,
                   carPosition=4,
                   currentLapInvalid=1)
     ]
     session = LapPacket().process(packet, session)
     self.assertEqual(
         session.lap_list, {
             2: {
                 'sector_1_time_ms': 10002,
                 'sector_2_time_ms': 20002,
                 'sector_3_time_ms': 49996,
                 'lap_number': 2,
                 'car_race_position': 4,
                 'pit_status': 2,
                 'is_valid': False
             }
         })
コード例 #2
0
 def test_lap_new_with_old_without_sector_2(self):
     session = Session(session_uid="vettel2021")
     session.lap_number_current = 1
     session.lap_list = {
         1: {
             "sector_1_time_ms": 0,
             "sector_2_time_ms": 0,
             "sector_3_time_ms": 30002,
             "lap_number": 1,
             "car_race_position": 1,
             "pit_status": 1,
             'is_valid': True
         }
     }
     session.process_lap_in_f1laps = MagicMock()
     packet = get_packet_mock()
     packet.lapData = [
         MagicMock(currentLapNum=2,
                   currentLapTime=80,
                   sector1TimeInMS=10002,
                   sector2TimeInMS=20002,
                   pitStatus=2,
                   carPosition=4,
                   lastLapTime=30.002)
     ]
     session = LapPacket().process(packet, session)
     self.assertEqual(
         session.lap_list, {
             1: {
                 "sector_1_time_ms": 0,
                 "sector_2_time_ms": 0,
                 "sector_3_time_ms": 30002,
                 "lap_number": 1,
                 "car_race_position": 1,
                 "pit_status": 1,
                 'is_valid': True
             },
             2: {
                 'sector_1_time_ms': 10002,
                 'sector_2_time_ms': 20002,
                 'sector_3_time_ms': 49996,
                 'lap_number': 2,
                 'car_race_position': 4,
                 'pit_status': 2,
                 'is_valid': True
             }
         })
     self.assertEqual(session.lap_number_current, 2)
     session.process_lap_in_f1laps.assert_not_called()
コード例 #3
0
 def test_process_no_lap_list_with_current_lap(self):
     session = Session(session_uid="vettel2021")
     session.lap_number_current = 1
     session.lap_list = {
         0: {
             "sector_1_time_ms": 0,
             "sector_2_time_ms": 0,
             "sector_3_time_ms": 30002,
             "lap_number": 1,
             "car_race_position": 1,
             "pit_status": 1,
             'is_valid': True
         }
     }
     packet = get_packet_mock()
     packet.carStatusData = [MagicMock(visualTyreCompound=7)]
     session = CarStatusPacket().process(packet, session)
     self.assertEqual(session.lap_list.get(session.lap_number_current),
                      None)
コード例 #4
0
 def test_get_f1laps_lap_times_list(self):
     session = Session(session_uid="vettel2021")
     self.assertEqual(session.get_f1laps_lap_times_list(), [])
     session.lap_list = {
         1: {
             "sector_1_time_ms": 10001,
             "sector_2_time_ms": 20001,
             "sector_3_time_ms": 30001,
             "lap_number": 1,
             "car_race_position": 1,
             "pit_status": 0
         },
         2: {
             "sector_1_time_ms": 10002,
             "sector_2_time_ms": 20002,
             "sector_3_time_ms": 30002,
             "lap_number": 2,
             "car_race_position": 1,
             "pit_status": 1,
             "tyre_compound_visual": 8
         },
     }
     self.assertEqual(session.get_f1laps_lap_times_list(),
                      [{
                          'car_race_position': 1,
                          'lap_number': 1,
                          'pit_status': 0,
                          'sector_1_time_ms': 10001,
                          'sector_2_time_ms': 20001,
                          'sector_3_time_ms': 30001,
                          "tyre_compound_visual": None,
                          'telemetry_data_string': None,
                      }, {
                          'car_race_position': 1,
                          'lap_number': 2,
                          'pit_status': 1,
                          'sector_1_time_ms': 10002,
                          'sector_2_time_ms': 20002,
                          'sector_3_time_ms': 30002,
                          "tyre_compound_visual": 8,
                          'telemetry_data_string': None,
                      }])
     # incomplete lap should not be returned
     session.lap_list = {
         1: {
             "sector_1_time_ms": 10001,
             "sector_2_time_ms": 20001,
             "sector_3_time_ms": 30001,
             "lap_number": 1,
             "car_race_position": 1,
             "pit_status": 0
         },
         2: {
             "sector_1_time_ms": 10002,
             "sector_2_time_ms": 20002,
             "sector_3_time_ms": 30002,
             "lap_number": 2,
             "car_race_position": 1,
             "pit_status": 1,
             "tyre_compound_visual": 16
         },
         3: {
             "sector_1_time_ms": 10002,
             "sector_2_time_ms": None,
             "sector_3_time_ms": 30002,
             "lap_number": 3,
             "car_race_position": 1,
             "pit_status": 1
         },
     }
     self.assertEqual(session.get_f1laps_lap_times_list(),
                      [{
                          'car_race_position': 1,
                          'lap_number': 1,
                          'pit_status': 0,
                          'sector_1_time_ms': 10001,
                          'sector_2_time_ms': 20001,
                          'sector_3_time_ms': 30001,
                          "tyre_compound_visual": None,
                          'telemetry_data_string': None,
                      }, {
                          'car_race_position': 1,
                          'lap_number': 2,
                          'pit_status': 1,
                          'sector_1_time_ms': 10002,
                          'sector_2_time_ms': 20002,
                          'sector_3_time_ms': 30002,
                          "tyre_compound_visual": 16,
                          'telemetry_data_string': None,
                      }])