Example #1
0
 def test_process_inlap(self):
     # First, test race (type 10), which should not process inlap
     session = F12021Session(123)
     session.session_type = 10
     session.lap_list[MOCK_LAP_NUMBER] = {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100}
     session.complete_lap_v2 = MagicMock()
     session.start_new_lap = MagicMock()
     packet = MockPacketOutLapData()
     packet.update_telemetry = MagicMock()
     packet.process(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 300}})
     self.assertEqual(session.complete_lap_v2.call_count, 1)
     self.assertEqual(session.start_new_lap.call_count, 0)
     self.assertEqual(packet.update_telemetry.call_count, 0)
     # Second, test time trial (type 13), which should process "inlap"
     session = F12021Session(123)
     session.session_type = 13
     session.lap_list[MOCK_LAP_NUMBER] = {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100}
     session.complete_lap_v2 = MagicMock()
     session.start_new_lap = MagicMock()
     packet = MockPacketOutLapData()
     packet.update_telemetry = MagicMock()
     packet.process(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'sector_1_ms': 0, 'sector_2_ms': 0, 'sector_3_ms': None, 'lap_number': 2, 'car_race_position': 10, 'pit_status': 0, 'is_valid': True}})
     self.assertEqual(session.complete_lap_v2.call_count, 0)
     self.assertEqual(session.start_new_lap.call_count, 0)
     self.assertEqual(packet.update_telemetry.call_count, 1)
Example #2
0
 def test_is_active_session(self):
     packet = MockPacketSessionData()
     self.assertEqual(packet.is_active_session(None), False)
     session = F12021Session(123)
     self.assertEqual(packet.is_active_session(session), False)
     session = F12021Session(MockPacketSessionData.header.sessionUID)
     self.assertEqual(packet.is_active_session(session), True)
Example #3
0
 def test_lap_should_be_sent_as_session(self):
     session = F12021Session(123)
     self.assertEqual(session.lap_should_be_sent_as_session(), False)
     session.session_type = 10
     self.assertEqual(session.lap_should_be_sent_as_session(), True)
     session.session_type = 13
     self.assertEqual(session.lap_should_be_sent_as_session(), False)
Example #4
0
 def test_lap_should_be_sent_to_f1laps(self):
     session = F12021Session(123)
     # Test lap not found
     self.assertEqual(session.lap_should_be_sent_to_f1laps(1), False)
     session.lap_list = {
         1: {
             1: {
                 'lap_number': 1,
                 'sector_1_ms': 11111,
                 'sector_2_ms': 22222,
                 'tyre_compound_visual': 16
             }
         }
     }
     # Test lap doesnt have all sectors
     self.assertEqual(session.lap_should_be_sent_to_f1laps(1), False)
     session.lap_list = {
         1: {
             'lap_number': 1,
             'sector_1_ms': 11111,
             'sector_2_ms': 22222,
             'sector_3_ms': 33333,
             'tyre_compound_visual': 16
         }
     }
     # Test success case
     self.assertEqual(session.lap_should_be_sent_to_f1laps(1), True)
     # Test lap was already sent to F1Laps
     self.assertEqual(session.lap_should_be_sent_to_f1laps(1), False)
Example #5
0
 def test_is_valid_for_f1laps_team_zero(self):
     session = F12021Session(123)
     session.team_id = 0
     session.session_type = 1
     self.assertEqual(session.is_valid_for_f1laps(), True)
     session.team_id = None
     self.assertEqual(session.is_valid_for_f1laps(), False)
Example #6
0
 def test_update_team_id(self):
     packet = MockPacketParticipantsData()
     session = F12021Session(123)
     session = packet.process(session)
     self.assertEqual(session.team_id, 5)
     session = packet.process(session)
     self.assertEqual(session.team_id, 5)
Example #7
0
 def test_send_lap_to_f1laps(self, mock_api):
     mock_api.return_value = MagicMock(status_code=201)
     session = F12021Session(123)
     session.track_id = 10
     session.team_id = 2
     session.session_type = 13
     session.lap_list = {
         1: {
             'lap_number': 1,
             'sector_1_ms': 11111,
             'sector_2_ms': 22222,
             'sector_3_ms': 33333,
             'tyre_compound_visual': 16
         }
     }
     self.assertEqual(session.send_lap_to_f1laps(1), None)
     mock_api.assert_called_with(track_id=10,
                                 team_id=2,
                                 conditions='dry',
                                 game_mode='time_trial',
                                 sector_1_time=11111,
                                 sector_2_time=22222,
                                 sector_3_time=33333,
                                 setup_data={},
                                 is_valid=True,
                                 telemetry_data_string=None)
Example #8
0
 def test_update_telemetry(self):
     session = F12021Session(123)
     session.telemetry.start_new_lap(MOCK_LAP_NUMBER)
     packet = MockPacketLapData()
     # Revert back to default, other tests might have overwritten it
     packet.lapData[0].currentLapTimeInMS = 1543
     session = packet.update_telemetry(session)
     self.assertEqual(session.telemetry.lap_dict[MOCK_LAP_NUMBER].frame_dict, {2345: [4321, 1543.0, None, None, None, None, None, None]})
Example #9
0
 def test_process(self, mock_send_to_f1laps):
     session = F12021Session(123)
     packet = MockPacketFinalClassificationData()
     packet.process(session)
     self.assertEqual(session.finish_position, 5)
     self.assertEqual(session.result_status, 6)
     self.assertEqual(session.points, 8)
     mock_send_to_f1laps.assert_called_with()
Example #10
0
 def test_process_new_lap(self):
     session = F12021Session(123)
     session.complete_lap_v2 = MagicMock()
     packet = MockPacketLapData()
     session = packet.process(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'car_race_position': 10, 'is_valid': True, 'lap_number': 2, 'pit_status': 0, 'sector_1_ms': 1000, 'sector_2_ms': 543, 'sector_3_ms': None}})
     self.assertEqual(session.telemetry.lap_dict[MOCK_LAP_NUMBER].frame_dict, {2345: [4321, 1543.0, None, None, None, None, None, None]})
     self.assertEqual(session.complete_lap_v2.call_count, 1)
Example #11
0
 def test_update_participants(self):
     packet = MockPacketParticipantsData()
     session = F12021Session(123)
     session = packet.process(session)
     self.assertEqual(len(session.participants), 3)
     self.assertEqual(session.participants[0].team, 5)
     self.assertEqual(session.participants[1].driver_index, 1)
     self.assertEqual(session.participants[2].name, "Mick Schumi")
     # Test that data won't be duplicated
     session = packet.process(session)
     self.assertEqual(len(session.participants), 3)
Example #12
0
 def test_process_current_lap(self):
     session = F12021Session(123)
     session.complete_lap_v2 = MagicMock()
     # Start new lap 2 so that we only test update, not create
     session.start_new_lap(MOCK_LAP_NUMBER)
     session.lap_list = {MOCK_LAP_NUMBER: {'car_race_position': 5, 'is_valid': True, 'pit_status': 1}}
     packet = MockPacketLapData()
     session = packet.process(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'car_race_position': 10, 'is_valid': True, 'lap_number': 2, 'pit_status': 1, 'sector_1_ms': 1000, 'sector_2_ms': 543, 'sector_3_ms': None}})
     self.assertEqual(session.telemetry.lap_dict[MOCK_LAP_NUMBER].frame_dict, {2345: [4321, 1543.0, None, None, None, None, None, None]})
     self.assertEqual(session.complete_lap_v2.call_count, 0)
Example #13
0
 def test_process_inlap_time_trial(self):
     session = F12021Session(123)
     session.session_type = 13 # time trial
     session.lap_list[MOCK_LAP_NUMBER] = {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100}
     session.complete_lap_v2 = MagicMock()
     session.start_new_lap = MagicMock()
     packet = MockPacketOutLapData()
     packet.update_telemetry = MagicMock()
     packet.process(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'car_race_position': 10, 'is_valid': True, 'lap_number': 2, 'pit_status': 0, 'sector_1_ms': 0, 'sector_2_ms': 0, 'sector_3_ms': None}})
     self.assertEqual(session.complete_lap_v2.call_count, 0)
     self.assertEqual(session.start_new_lap.call_count, 0)
     self.assertEqual(packet.update_telemetry.call_count, 1)
Example #14
0
 def test_update_participants(self):
     session = F12021Session(123)
     packet = MockPacketFinalClassificationData()
     # Processing without participants should log a warning, nothing else
     packet.process(session)
     self.assertEqual(session.participants, [])
     # Now add a participant and process classification
     session.add_participant(name="Player",
                             team=0,
                             driver=255,
                             driver_index=0)
     packet.process(session)
     self.assertEqual(len(session.participants), 1)
     self.assertEqual(session.participants[0].points, 8)
Example #15
0
 def test_process_new_lap_with_previous(self):
     session = F12021Session(123)
     session.complete_lap_v2 = MagicMock()
     # Start new lap 1 so that we test updating previous
     prev_lap_num = MOCK_LAP_NUMBER - 1
     session.start_new_lap(prev_lap_num)
     session.lap_list[prev_lap_num] = {'sector_1_ms': 500, 'sector_2_ms': 400}
     packet = MockPacketLapData()
     session = packet.process(session)
     self.assertEqual(session.lap_list, 
                      {prev_lap_num: {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 300},
                       MOCK_LAP_NUMBER: {'car_race_position': 10, 'is_valid': True, 'lap_number': 2, 'pit_status': 0, 'sector_1_ms': 1000, 'sector_2_ms': 543, 'sector_3_ms': None}})
     self.assertEqual(session.telemetry.lap_dict[MOCK_LAP_NUMBER].frame_dict, {2345: [4321, 1543.0, None, None, None, None, None, None]})
     self.assertEqual(session.complete_lap_v2.call_count, 1)
Example #16
0
 def test_update_current_lap(self):
     session = F12021Session(123)
     session.start_new_lap(MOCK_LAP_NUMBER)
     packet = MockPacketLapData()
     session = packet.update_current_lap(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'car_race_position': 10, 'is_valid': True, 'lap_number': 2, 'pit_status': 0, 'sector_1_ms': 1000, 'sector_2_ms': 543, 'sector_3_ms': None}})
     packet.lapData[0].currentLapInvalid = 1
     packet.lapData[0].carPosition = 9
     packet.lapData[0].pitStatus = 0
     packet.lapData[0].currentLapTimeInMS = 2000
     session = packet.update_current_lap(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'car_race_position': 9, 'is_valid': False, 'lap_number': 2, 'pit_status': 0, 'sector_1_ms': 1000, 'sector_2_ms': 543, 'sector_3_ms': 457}})
Example #17
0
 def test_has_final_classification(self):
     session = F12021Session(123)
     self.assertEqual(session.has_final_classification(), False)
     # A positive result status on the session itself always is true
     session.result_status = 5
     self.assertEqual(session.has_final_classification(), True)
     session.result_status = None
     # Participants with no result status - false
     session.add_participant(name="Player",
                             team=0,
                             driver=255,
                             driver_index=0)
     self.assertEqual(session.has_final_classification(), False)
     session.participants[0].result_status = 5
     self.assertEqual(session.has_final_classification(), True)
Example #18
0
 def create_session(self):
     session = F12021Session(session_uid=self.header.sessionUID)
     session.session_udp_uid = self.header.sessionUID
     session.set_session_type(self.sessionType)
     if not self.sessionType:
         log.warning("Got Session packet without sessionType")
     session.track_id = self.trackId
     session.ai_difficulty = self.aiDifficulty
     if self.networkGame == 1:
         session.is_online_game = True
     if self.weather not in session.weather_ids:
         session.weather_ids.append(self.weather)
     session.start()
     log.debug("Session vals: season %s weekend %s session %s UID %s" %
               (self.seasonLinkIdentifier, self.weekendLinkIdentifier,
                self.sessionLinkIdentifier, self.header.sessionUID))
     return session
Example #19
0
 def test_string(self):
     session = F12021Session(123)
     session.team_id = 1
     session.lap_list = {2: []}
     self.assertEqual(
         str(session),
         "F12021 Session 123 (None, team 1, type None, offline, 1 laps)")
     session.track_id = 2
     self.assertEqual(
         str(session),
         "F12021 Session 123 (Shanghai, team 1, type None, offline, 1 laps)"
     )
     session.session_type = 6
     self.assertEqual(
         str(session),
         "F12021 Session 123 (Shanghai, team 1, type qualifying_2, offline, 1 laps)"
     )
Example #20
0
 def test_get_classification_list(self):
     session = F12021Session(123)
     classifications = session.get_classification_list()
     self.assertEqual(classifications, [])
     session.add_participant(name="Player",
                             team=0,
                             driver=255,
                             driver_index=0)
     session.participants[0].result_status = 5
     session.participants[0].position = 20
     session.add_participant(name="Mick Schumi",
                             team=1,
                             driver=1,
                             driver_index=1)
     session.participants[1].result_status = 4
     session.participants[1].position = 5
     session.participants[1].points = 10
     session.participants[1].grid_position = 19
     classifications = session.get_classification_list()
     self.assertEqual(classifications, [{
         'driver': 255,
         'driver_index': 0,
         'team': 0,
         'points': None,
         'finish_position': None,
         'grid_position': None,
         'result_status': 5,
         'lap_time_best': None,
         'race_time_total': None,
         'penalties_time_total': None,
         'penalties_number': None
     }, {
         'driver': 1,
         'driver_index': 1,
         'team': 1,
         'points': 10,
         'finish_position': None,
         'grid_position': 19,
         'result_status': 4,
         'lap_time_best': None,
         'race_time_total': None,
         'penalties_time_total': None,
         'penalties_number': None
     }])
Example #21
0
 def test_process_inlap_quali_with_pit(self):
     session = F12021Session(123)
     session.session_type = 5 # Q1
     session.lap_list[MOCK_LAP_NUMBER] = {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100}
     session.complete_lap_v2 = MagicMock()
     session.start_new_lap = MagicMock()
     packet = MockPacketQualiOutLapData()
     packet.update_telemetry = MagicMock()
     packet.process(session)
     self.assertEqual(session.lap_list[MOCK_LAP_NUMBER], {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100})
     self.assertEqual(session.complete_lap_v2.call_count, 1)
     self.assertEqual(session.start_new_lap.call_count, 0)
     self.assertEqual(packet.update_telemetry.call_count, 0)
     # Now let's process a normal lap, which doesn't have pit data - it should overwrite
     packet = MockPacketLapData()
     packet.update_telemetry = MagicMock()
     packet.process(session)
     self.assertEqual(session.lap_list, 
                      {MOCK_LAP_NUMBER: {'car_race_position': 10, 'is_valid': True, 'lap_number': 2, 'pit_status': 0, 'sector_1_ms': 1000, 'sector_2_ms': 543, 'sector_3_ms': None}})
     self.assertEqual(session.complete_lap_v2.call_count, 1)
     self.assertEqual(session.start_new_lap.call_count, 0)
     self.assertEqual(packet.update_telemetry.call_count, 1)
Example #22
0
 def test_send_session_to_f1laps(self, mock_api):
     mock_api.return_value = True, "vettel2021"
     session = F12021Session(123)
     session.track_id = 10
     session.team_id = 2
     session.session_type = 10
     session.lap_list = {}
     session.send_session_to_f1laps()
     self.assertEqual(session.f1_laps_session_id, "vettel2021")
     mock_api.assert_called_with(f1laps_session_id=None,
                                 track_id=10,
                                 team_id=2,
                                 session_uid=123,
                                 conditions='dry',
                                 session_type='race',
                                 finish_position=None,
                                 points=None,
                                 result_status=None,
                                 lap_times=[],
                                 setup_data={},
                                 is_online_game=False,
                                 ai_difficulty=None,
                                 classifications=[])
Example #23
0
 def test_process_active(self):
     packet = MockPacketSessionData()
     session = F12021Session(MockPacketSessionData.header.sessionUID)
     self.assertEqual(packet.process(session), session)
Example #24
0
 def test_is_inlap_race_distance_low_with_sectors(self):
     session = F12021Session(123)
     session.lap_list[MOCK_LAP_NUMBER] = {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100}
     packet = MockPacketOutLapData()
     is_outlap = packet.is_race_inlap(session, MOCK_LAP_NUMBER)
     self.assertEqual(is_outlap, True)
Example #25
0
 def test_is_inlap_race_distance_low_no_sectors(self):
     session = F12021Session(123)
     packet = MockPacketOutLapData()
     is_outlap = packet.is_race_inlap(session, MOCK_LAP_NUMBER)
     self.assertEqual(is_outlap, False)
Example #26
0
 def test_get_track_name(self):
     session = F12021Session(123)
     session.track_id = 5
     self.assertEqual(session.get_track_name(), "Monaco")
Example #27
0
 def test_packet_should_update_lap_time_trial(self):
     session = F12021Session(123)
     session.session_type = 13 # time trial
     session.lap_list[MOCK_LAP_NUMBER] = {'sector_1_ms': 500, 'sector_2_ms': 400, 'sector_3_ms': 100}
     packet = MockPacketOutLapData()
     self.assertEqual(packet.packet_should_update_lap(session, MOCK_LAP_NUMBER), True)
Example #28
0
 def test_get_session_type(self):
     session = F12021Session(123)
     session.session_type = 7
     self.assertEqual(session.get_session_type(), "qualifying_3")