예제 #1
0
 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"
         )
예제 #2
0
 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"
         )
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
 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")
예제 #7
0
 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")
예제 #8
0
 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"
         )
예제 #9
0
 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>'."
         )
예제 #10
0
    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.'
            )
예제 #11
0
    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'
            )
예제 #12
0
    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')
예제 #13
0
 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.'
             )
예제 #14
0
 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."
             )