Пример #1
0
 def test_init_when_one_of_drivers_is_not_of_class_car_then_raise_type_error(
         self):
     with self.assertRaises(TypeError):
         Race([
             Driver('Ivo', Car('Opel', 'Astra', 240)),
             ('Rado', Car('Pegeout', '107', 180))
         ], 0.5, 'Pandarace', 3)
Пример #2
0
 def test_init_when_championship_name_is_not_str_then_return_type_error(
         self):
     with self.assertRaises(TypeError):
         Race([
             Driver('Ivo', Car('Opel', 'Astra', 240)),
             Driver('Rado', Car('Pegeout', '107', 180))
         ], 0.5, 12, 3)
Пример #3
0
def set_up_drivers(file_name):
    with open(file_name) as file:
        drivers_data = json.load(file)
    # print(drivers_data)
    drivers = []
    for record in drivers_data['people']:
        new_car = Car(record['car'], record['model'], record['max_speed'])
        new_driver = Driver(record['name'], new_car)
        drivers.append(new_driver)
    return drivers
Пример #4
0
 def test_if_car_gets_printed_out_with_dunder(self):
     test_subject = Car('a', 'b', 300)
     expected_result = 'a b with 300 maximum speed.'
     self.assertEqual(str(test_subject), expected_result)
Пример #5
0
 def test_if_driver_gets_printed_out_with_dunder(self):
     test_car = Car('c', 'd', 300)
     test_subject = Driver('a', test_car)
     expected_result = 'a has a c d with 300 maximum speed.'
     self.assertEqual(str(test_subject), expected_result)
Пример #6
0
 def test_init_when_model_is_not_str_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Car('Opel', 3, 240)
Пример #7
0
 def test_init_when_race_number_is_not_int_then_return_type_error(self):
     with self.assertRaises(TypeError):
         Race([
             Driver('Ivo', Car('Opel', 'Astra', 240)),
             Driver('Rado', Car('Pegeout', '107', 180))
         ], 0.5, 'Pandarace', '3')
Пример #8
0
 def test_init_when_crash_chance_is_not_float_then_raise_value_error(self):
     with self.assertRaises(ValueError):
         Race([
             Driver('Ivo', Car('Opel', 'Astra', 240)),
             Driver('Rado', Car('Pegeout', '107', 180))
         ], 1.5, 'Pandarace', 3)
Пример #9
0
 def test_init_when_car_is_not_str_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Car(False, 'Astra', 240)
Пример #10
0
 def test_init_when_drivers_is_not_list_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Race((Driver('Ivo', Car('Opel', 'Astra', 240)),
               Driver('Rado', Car('Pegeout', '107', 180))), 0.5,
              'Pandarace', 3)
Пример #11
0
 def test_str_dunder(self):
     test_driver = Driver('Ivo', Car('Opel', 'Astra', 240))
     expected_result = 'Name: Ivo\nCar: Opel\nModel: Astra\nMax speed: 240\n'
     self.assertEqual(str(test_driver), expected_result)
Пример #12
0
 def test_init_when_driver_is_not_str_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Driver(34, Car('Opel', 'Astra', 240))
Пример #13
0
 def test_str_dunder(self):
     test_car = Car('Opel', 'Astra', 240)
     expected_result = 'Car: Opel\nModel: Astra\nMax speed: 240\n'
     self.assertEqual(str(test_car), expected_result)
Пример #14
0
 def test_init_when_max_speed_is_not_str_then_raise_type_error(self):
     with self.assertRaises(TypeError):
         Car('Opel', 'Astra', '240')