def setUp(self): """Set up sub-objects for RestaurantRatings tests""" self.rrobj = rr.RestaurantRatings([ rr.RestaurantRating("The Tavern", 10), rr.RestaurantRating("Gastropub", 9), rr.RestaurantRating("Snack Shack", 5) ])
def test_save_to_file(self): mockobj = mock.mock_open() rrobj = rr.RestaurantRatings([rr.RestaurantRating("The Tavern", 10)]) with mock.patch("builtins.open", mockobj) as mock_f: rrobj.save_to_file("mockfile") mockobj.assert_called_once_with("mockfile", "w") mockobj().write.assert_has_calls([ mock.call("The Tavern"), mock.call(":"), mock.call("10"), ])
def test_init_with_source(self): rrobj = rr.RestaurantRatings([rr.RestaurantRating("The Tavern", 10)]) self.assertEqual(len(rrobj.ratings), 1) self.assertEqual(rrobj.ratings[0].name, "The Tavern") self.assertEqual(rrobj.ratings[0].rating, 10)
def setUp(self): self.ratings = rr.RestaurantRatings([ rr.RestaurantRating("The Tavern", 10), rr.RestaurantRating("Gastropub", 7) ])
def test_lt_false(self): rating_1 = rr.RestaurantRating("The Tavern", 10) rating_2 = rr.RestaurantRating("Gastropub", 9) self.assertFalse(rating_1 < rating_2)
def test_lt_true(self): rating_1 = rr.RestaurantRating("The Tavern", 9) rating_2 = rr.RestaurantRating("Gastropub", 10) self.assertLess(rating_1, rating_2)
def test_eq_false(self): rating_1 = rr.RestaurantRating("The Tavern", 10) rating_2 = rr.RestaurantRating("Gastropub", 9) self.assertNotEqual(rating_1, rating_2)
def test_update_rating(self): rating = rr.RestaurantRating("The Tavern", 10) rating.update_rating(2) self.assertEqual(rating.rating, 2)
def test_init(self): rating = rr.RestaurantRating("The Tavern", 10) self.assertEqual(rating.name, "The Tavern") self.assertEqual(rating.rating, 10)