Exemple #1
0
 def test_read_in_file_for_open_with_IOError(self):
     data = self.URL_VALID_IMAGE_1 + '\n' + self.URL_VALID_IMAGE_2
     fake_file = io.StringIO(data)
     with patch('builtins.open', return_value=fake_file,
                create=True) as mock_file:
         mock_file.side_effect = IOError
         self.assertEqual(read_in_file("foo.bar"), [])
Exemple #2
0
 def test_download_by_text_file_with_broken_image_urls(self):
     data = self.URL_BROKEN_LINK + '\n' + self.URL_VALID_IMAGE_2
     fake_file = io.StringIO(data)
     with patch('builtins.open', return_value=fake_file, create=True):
         url_list = read_in_file("foo.bar")
     self.assertEqual(download_by_url_list(url_list), 1)
Exemple #3
0
 def test_read_in_file_with_empty_input_file(self):
     data = ""
     fake_file = io.StringIO(data)
     with patch('builtins.open', return_value=fake_file, create=True):
         self.assertEqual(read_in_file("foo.bar"), [])
Exemple #4
0
 def test_read_in_file_with_invalid_input_file(self):
     self.assertEqual(read_in_file("foo.bar"), [])
Exemple #5
0
 def test_read_in_file_with_valid_input_file(self):
     data = self.URL_VALID_IMAGE_1 + '\n' + self.URL_VALID_IMAGE_2
     fake_file = io.StringIO(data)
     with patch('builtins.open', return_value=fake_file, create=True):
         self.assertEqual(read_in_file("foo.bar"), data.split())
Exemple #6
0
 def test_read_in_file_for_open(self):
     filename = "foo.bar"
     with patch("builtins.open", mock_open(read_data="data")) as mock_file:
         read_in_file(filename)
         mock_file.assert_called_with(filename, "r")