class FileIOPartsGeneratorTestCase(TestCase): def setUp(self): super(FileIOPartsGeneratorTestCase, self).setUp() self.generator = FileIOPartsGenerator() self.generator.part_size = 10 def test_generate_parts(self): fd = StringIO("x" * 5 + "y" * 10 + "z" * 13) generated = [entity for entity in self.generator.generate_parts(fd)] self.assertEqual(generated, [('xxxxxyyyyy', 1), ('yyyyyzzzzz', 2), ('zzzzzzzz', 3)]) def test_default_part_size(self): self.assertEqual(FileIOPartsGenerator.part_size, 5 * 1024 * 1024) def test_count_parts_for_stringio_type(self): fd = StringIO("x" * 53) count = self.generator.count_parts(fd) self.assertEqual(count, 6) fd = StringIO("x" * 30) count = self.generator.count_parts(fd) self.assertEqual(count, 3) def test_count_parts_for_file_type(self): path = self.mktemp() with open(path, "w") as fd: fd.write("x" * 53) fd = open(path) count = self.generator.count_parts(fd) self.assertEqual(count, 6) def test_count_parts_for_other_type(self): count = self.generator.count_parts([]) self.assertEqual(count, "?")