def test_allows_cars_to_enter(self): """ Ensure the garage allows Car object to enter """ c = Car(color='yellow', make='honda', model='civic') g = Garage(name='test_garage') g.enter(c)
def test_allows_cars_to_exit(self): """ Ensure vehicles can leave the garage """ d = Car(color='yellow', make='honda', model='civic') g = Garage(name='test_garage') g.enter(d) g.exit(d)
def test_ensure_cars_enter_fully(self): """ Ensure vehicle is in garage after it enters (eg: vehicle in garage == True) """ d = Car(color='yellow', make='honda', model='civic') g = Garage(name='test_garage') g.enter(d) self.assertEqual(d in g.vehicles, True)
def test_initial_state_is_stopped(self): """ Ensure the a car's initial state is "stopped" """ c = Car(color='blue', make='honda', model='civic') try: self.assertEqual(c.state, 'stopped') except AssertionError: self.fail("Was not able to return an initial state of stopped")
def test_description(self): """ Ensure the car description return a string of: "color, make model" """ c = Car(color='blue', make='honda', model='civic') d = c.description try: self.assertEqual(d, '{} {} {}'.format(c.color, c.make, c.model)) except AssertionError: self.fail("Was not able to return a string of: color, make model")
def test_car_is_a_vehicle(self): """ Ensure a car object is also an instance of BaseVehicle """ c = Car(color='blue', make='honda', model='civic') try: self.assertEqual(isinstance(c, BaseVehicle), True) except AssertionError: self.fail( "Was not able to ensure a car object is also an instance of BaseVehicle" )
def test_str_builtin(self): """ Ensure the car evaluates to a string of "I am a <car color>, <car make>, <car model>." """ c = Car(color='blue', make='honda', model='civic') try: self.assertEqual(str(c), 'I am a blue honda civic.') except AssertionError: self.fail( "Was not able to ensure the car evaluates to a string of 'I am a <car color> <car make> <car model>'." )
def test_state_after_start(self): """ Ensure the car's state is "started" after using start method """ c = Car(color='blue', make='honda', model='civic') c.start() try: self.assertEqual(c.state, 'started') except AssertionError: self.fail( "Was not able to return the car's state as started after using start method" )
def test_len_builtin(self): """ Ensure that the length of the garage matches the number of vehicles parked in it """ g = Garage(name='test_garage') a = Car(color='red', make='honda', model='civic') b = Car(color='white', make='honda', model='civic') c = Car(color='blue', make='honda', model='civic') g.enter(a) g.enter(b) g.enter(c) manual_list = len([a, b, c]) garage_test_list = len([v for v in g]) try: self.assertEqual(garage_test_list, manual_list) except AssertionError: self.fail( 'Could not ensure we can iterate over garage vehicles by trying to iterate over the garage itself.' )
def test_iter_builtin(self): """ Ensure we can iterate over garage vehicles by trying to iterate over the garage itself """ gg = Garage(name='test_garage') a = Car(color='red', make='honda', model='civic') b = Car(color='white', make='honda', model='civic') c = Car(color='green', make='honda', model='civic') gg.enter(a) gg.enter(b) gg.enter(c) manual_list = [a, b, c] garage_test_list = [v for v in gg] try: self.assertEqual(garage_test_list, manual_list) except AssertionError: self.fail( 'Could not ensure we can iterate over garage vehicles by trying to iterate over the garage itself' )
def test_ensure_cars_exit_fully(self): """ Vehicle is not in garage after it exits """ d = Car(color='yellow', make='honda', model='civic') g = Garage(name='test_garage') g.enter(d) g.exit(d) try: self.assertEqual(d in g.vehicles, False) except AssertionError: self.fail( 'Could not ensure vehicle is not in garage after it exits')
def test_state_read_only(self): """ Ensure the car state attribute is read only and throws AttributeError if someone tries to assign a value directly """ c = Car(color='blue', make='honda', model='civic') try: try: c.state = 'test' except AttributeError as a: self.assertEqual(str(a), "can't set attribute") except AssertionError: self.fail( "Was not able to ensure he car state attribute is read only and throws AttributeError if someone tries to assign a value directly" )
def test_raise_lookup_error_on_exit(self): """ Ensure that garage raises LookupError if vehicle attempts to exit but was never in garage. """ d = Car(color='yellow', make='honda', model='civic') g = Garage(name='test_garage') try: g.exit(d) except LookupError as e: try: self.assertEqual(str(e), "That vehicle is not in test_garage.") except AssertionError: self.fail( 'Could not ensure that garage raises LookupError if vehicle attempts to exit but was never in garage.' )
def test_color_requirement(self): """ Ensure the car requires a color argument during instantiation """ try: c = Car(make='honda', model='civic') except TypeError as e: try: self.assertEqual( str(e), "__init__() missing 1 required positional argument: 'color'" ) except AssertionError: self.fail( "Was not able to ensure the car requires a color argument during instantiation." )