def test_good_limit_filling(self): """ Test filling with limit. """ for limits, car in zip(self.ex1_prc, self.ex1): for (prc, ans) in limits: c = Car(*car) self.assertEqual(c.fill_tank(limit=prc), ans)
def test_bad_input_methods(self): for car in self.ex1: c = Car(*car) with self.assertRaises(TypeError): c.fill_tank(liters='sto') with self.assertRaises(TypeError): c.fill_tank(limit='sto') with self.assertRaises(TypeError): c.fill_tank(limit=1., liters=100) with self.assertRaises(ValueError): c.fill_tank(other=10)
def test_bad_pool(self): exs = [ 'sto', 1.1, 0.5, '20', [], [1,23] ] for e in exs: with self.assertRaises(TypeError): Car.get_carpool(e) with self.assertRaises(TypeError): DieselCar.get_carpool(e)
def test_good_full_filling(self): """ Checking filling the tank to maximum with all the methods. """ for car, ans in zip(self.ex1, self.ex1_full): c = Car(*car) self.assertEqual(c.fill_tank(), ans) c = Car(*car) self.assertEqual(c.fill_tank(limit=1.), ans) c = Car(*car) self.assertEqual(c.fill_tank(liters=ans), ans)
def test_good_empty_filling(self): """ Filling tank with nothing. """ for car in self.ex1: c = Car(*car) self.assertEqual(c.fill_tank(liters=0), 0) c = Car(*car) self.assertEqual(c.fill_tank(limit=0.), 0)
def test_good_pool(self): pools = [ 0, 1, 2, 3, 10, 100 ] for nr in pools: cp = Car.get_carpool(nr) cps = [c.brand for c in cp] self.assertEqual(len(cps), nr) dp = DieselCar.get_carpool(nr) dps = [d.brand for d in dp] self.assertEqual(len(dps), nr)
def test_numers_liters(self): for car, (f, a) in zip(self.ex_numbers, self.ex_numbers_liters): c = Car(*car) self.assertEqual(c.fill_tank(liters=f), a)
def test_numbers_limit(self): for car, (f, a) in zip(self.ex_numbers, self.ex_numbers_limit): c = Car(*car) res = c.fill_tank(limit=f) self.assertEqual(res, a)
def test_method_pool(self): for i in [10,20,30]: cars = Car.get_carpool(i) for c in cars: self.assertEqual(c.fill_tank(limit=0.), 0) self.assertEqual(c.fill_tank(liters=0), 0)
def test_bad_liters(self): for liters, car in zip(self.ex1_bad_liters, self.ex1): for e in liters: c = Car(*car) with self.assertRaises(ValueError): c.fill_tank(liters=e)
def test_good_liters_filling(self): for liters, car in zip(self.ex1_liters, self.ex1): for ans in liters: c = Car(*car) self.assertEqual(c.fill_tank(liters=ans), ans)
def test_good_creating(self): for car in self.ex1: c = Car(*car) d = DieselCar(*car) self.assertEqual(str(c), info(c, car)) self.assertEqual(str(d), info(d, car))
import unittest from zadanie2 import Car, get_carpool, DieselCar test_car = Car('Test', 100, 70) test_diesel_car = DieselCar('Test_diesel', 100, 10) brand_car = [ 'Peugeot', 'Volvo', 'Skoda', 'Fiat', 'Ford', 'Doge', 'BMW', 'Toyota', 'Mazda', 'Jaguar' ] class TestZadanie2(unittest.TestCase): def test_fill_tank_over_limit(self): with self.assertRaises(Exception) as context: test_car.fill_tank(limit=1.1) self.assertTrue( 'You can add limit only on range 0 to 1' in str(context.exception)) def test_fill_tank_to_many_parameters(self): with self.assertRaises(Exception) as context: test_car.fill_tank(limit=0.5, liters=10) self.assertTrue( "You can add only one parameters they are mutually exclusive" in str(context.exception)) def test_fill_tank_under_limit(self): with self.assertRaises(Exception) as context: limit = 0.5 test_car.fill_tank(limit=limit) self.assertTrue(