Пример #1
0
 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))
Пример #2
0
 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'))
Пример #3
0
 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'))