class TestPlane(unittest.TestCase): def setUp(self): self.plane = Plane() self.plane.land() def test_land_sets_grounded_status_to_true(self): self.assertEqual(self.plane.grounded, True) def test_land_raises_error_if_plane_grounded(self): self.assertRaises(TypeError, self.plane.land) def test_take_off_sets_grounded_status_to_false(self): self.plane.take_off() self.assertEqual(self.plane.grounded, False) def test_take_off_raises_error_if_plane_not_grounded(self): self.plane.take_off() self.assertRaises(TypeError, self.plane.take_off)
class PlaneTest(unittest.TestCase): def setUp(self): self.plane = Plane() def test_planes_can_take_off(self): self.plane.take_off() self.assertTrue(self.plane.flying, 'plane does not correctly take off') def test_planes_can_land(self): self.plane.take_off() self.plane.land() self.assertFalse(self.plane.flying, 'plane does not correctly land') def test_flying_planes_cannot_take_off(self): self.plane.take_off() with self.assertRaises(Exception): self.plane.take_off() def test_landed_planes_cannot_land(self): self.plane.land() with self.assertRaises(Exception): self.plane.land()