示例#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 test_init(self):
     rrobj = rr.RestaurantRatings()
     self.assertEqual(len(rrobj.ratings), 0)
     self.assertEqual(rrobj.ratings, [])
示例#5
0
 def setUp(self):
     self.ratings = rr.RestaurantRatings([
         rr.RestaurantRating("The Tavern", 10),
         rr.RestaurantRating("Gastropub", 7)
     ])