Exemple #1
0
 def test_read_in_chunks(self):
     """File chunking works with different size chunks."""
     for chunk_size in [1, 2, 3, self._file_size - 1, self._file_size, self._file_size + 1]:
         chunks = list(file_hash._read_in_chunks(open('/hello_world'), chunk_size=chunk_size))
         # Check the number of chunks, size of each chunk, and their reconstructed content.
         self.assertEqual(int(math.ceil(self._file_size / chunk_size)), len(chunks))
         self.assertTrue(all(1 <= len(chunk) <= chunk_size for chunk in chunks))
         self.assertEqual(self._test_contents, ''.join(chunks))
Exemple #2
0
 def test_read_in_chunks_empty_file(self):
     """File chunking returns an empty list if no file contents."""
     chunks = list(file_hash._read_in_chunks(open('/empty_file')))
     self.assertEqual([], chunks)