コード例 #1
0
 def test_get_lines_file(self):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     result = race_manager._get_lines_file()
     self.assertEquals(result, [
         '23:49:08.277      038 – MARIO                           1\t\t1:02.852                        44,275\n',
         '23:49:10.858      033 – R.BARRICHELLO                     1\t\t1:04.352                        43,243'
     ])  # noqa
コード例 #2
0
    def test_get_positions(self, mock_s_position):
        position = Position(1, self.driver, 1, 60001)
        mock_s_position.return_value = [position]

        race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
        result = race_manager._get_positions([])
        self.assertEqual(type(result[0]), Position)
コード例 #3
0
    def test_get_laps_with_exception_file_not_math_with_pattern(self):
        with self.assertRaises(ManagerException) as error:
            race_manager = RaceManager(
                self.fixtures_path +
                '/file_not_match_with_pattern.log')  # noqa
            race_manager._get_lap_service()

        self.assertEqual(str(error.exception), 'File not match with pattern')
コード例 #4
0
    def test_get_laps(self):
        lines = [
            "23:49:08.277      038 – MARIO                           1		1:02.852                        44,275"
        ]  # noqa

        race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
        result = race_manager._get_laps(lines)
        self.assertEqual(type(result[0]), Lap)
コード例 #5
0
    def test_get_drivers_lap_after_winner(self, mock_s_position):
        position = Position(1, self.driver, 1, 60001)
        position_2 = Position(2, self.driver_2, 1, 60002)
        mock_s_position.return_value = [position, position_2]

        race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
        result = race_manager._get_drivers_lap_after_winner([])
        self.assertEqual(type(result[0]), Position)
        self.assertEqual(result[0].delay_after_winner, 1)
コード例 #6
0
    def test_show_result_with_expection(self):
        with self.assertRaises(ManagerException) as error:
            race_manager = RaceManager(self.fixtures_path + '/file_empty.log')
            race_manager.show_result()

        self.assertEqual(str(error.exception), 'File is empty')
コード例 #7
0
 def test_show_result(self, mock_stdout):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     race_manager.show_result()
     self.assertEqual(
         mock_stdout.getvalue(),
         '1 038-MARIO 1 1:02.852\n2 033-R.BARRICHELLO 1 1:04.352\n')  # noqa
コード例 #8
0
 def test_get_best_drivers_lap(self):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     result = race_manager._get_best_drivers_lap()
     self.assertEqual(type(result[0]), Lap)
コード例 #9
0
    def get_lap_service_with_expection(self):
        with self.assertRaises(ManagerException) as error:
            race_manager = RaceManager(self.fixtures_path + '/file_empty.log')
            race_manager._get_lap_service()

        self.assertEqual(str(error.exception), 'File is empty')
コード例 #10
0
 def get_lap_service(self):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     result = race_manager._get_lap_service()
     self.assertEqual(type(result), LapService)
コード例 #11
0
 def test_show_time_drivers_after_winner(self, mock_stdout):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     race_manager.show_time_drivers_after_winner()
     self.assertEqual(mock_stdout.getvalue(),
                      '033-R.BARRICHELLO 1 0:01.500\n')  # noqa
コード例 #12
0
 def test_show_drivers_average_speed(self, mock_stdout):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     race_manager.show_drivers_average_speed()
     self.assertEqual(
         mock_stdout.getvalue(),
         '038-MARIO 44.275\n033-R.BARRICHELLO 43.243\n')  # noqa
コード例 #13
0
 def test_show_best_lap_of_race(self, mock_stdout):
     race_manager = RaceManager(self.fixtures_path + '/file_with_laps.log')
     race_manager.show_best_lap_of_race()
     self.assertEqual(mock_stdout.getvalue(),
                      '038-MARIO 1:02.852\n')  # noqa
コード例 #14
0
def main():

    try:
        opts, args = getopt.getopt(sys.argv[1:], "h:f:", ["file="])
    except getopt.GetoptError:
        show_available_commands()
        sys.exit()

    for opt, arg in opts:
        if opt == '-h':
            print('mkart -f <file.log>')
            sys.exit()
        elif opt in ("-f", "--file"):
            try:
                race_manager = RaceManager(arg)

                show_text_result()
                race_manager.show_result()
                show_text_line_break()

                show_test_best_driver_lap()
                race_manager.show_best_drivers_lap()
                show_text_line_break()

                show_test_best_lap_of_race_lap()
                race_manager.show_best_lap_of_race()
                show_text_line_break()

                show_test_drivers_average_speed()
                race_manager.show_drivers_average_speed()
                show_text_line_break()

                show_text_time_drivers_after_winner()
                race_manager.show_time_drivers_after_winner()
                show_text_line_break()

            except ManagerException as e:
                print(e)
            sys.exit()

    show_available_commands()
    sys.exit()