예제 #1
0
 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)
     ])
예제 #2
0
    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"),
        ])
예제 #3
0
 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)
예제 #4
0
 def setUp(self):
     self.ratings = rr.RestaurantRatings([
         rr.RestaurantRating("The Tavern", 10),
         rr.RestaurantRating("Gastropub", 7)
     ])
예제 #5
0
 def test_lt_false(self):
     rating_1 = rr.RestaurantRating("The Tavern", 10)
     rating_2 = rr.RestaurantRating("Gastropub", 9)
     self.assertFalse(rating_1 < rating_2)
예제 #6
0
 def test_lt_true(self):
     rating_1 = rr.RestaurantRating("The Tavern", 9)
     rating_2 = rr.RestaurantRating("Gastropub", 10)
     self.assertLess(rating_1, rating_2)
예제 #7
0
 def test_eq_false(self):
     rating_1 = rr.RestaurantRating("The Tavern", 10)
     rating_2 = rr.RestaurantRating("Gastropub", 9)
     self.assertNotEqual(rating_1, rating_2)
예제 #8
0
 def test_update_rating(self):
     rating = rr.RestaurantRating("The Tavern", 10)
     rating.update_rating(2)
     self.assertEqual(rating.rating, 2)
예제 #9
0
 def test_init(self):
     rating = rr.RestaurantRating("The Tavern", 10)
     self.assertEqual(rating.name, "The Tavern")
     self.assertEqual(rating.rating, 10)