def _saveToFile(self, data, localPath, expectedSize=None): if hasattr(data, 'save_as'): data.save_as(localPath) else: from multipart import copy_file if not hasattr(data,'read'): import cStringIO as StringIO data = StringIO.StringIO(data) f = open(localPath,"w") if f: copy_file(data, f) f.close() if expectedSize is not None: actualSize = os.path.getsize(localPath) if actualSize != expectedSize: raise ValueError('_saveToFile: Size error. Expected: %s, Actual: %s' % (expectedSize, actualSize))
def test_copyfile(self): source = BytesIO(to_bytes('abc')) target = BytesIO() self.assertEqual(mp.copy_file(source, target), 3) target.seek(0) self.assertEqual(target.read(), to_bytes('abc'))
def test_copyfile(self): source = BytesIO(tob('abc')) target = BytesIO() self.assertEqual(mp.copy_file(source, target), 3) target.seek(0) self.assertEqual(target.read(), tob('abc'))