コード例 #1
0
 def _get_fileobj_from_filename(self, filename):
     f = DeferredOpenFile(
         filename, mode='wb', open_function=self._osutil.open)
     # Make sure the file gets closed and we remove the temporary file
     # if anything goes wrong during the process.
     self._transfer_coordinator.add_failure_cleanup(f.close)
     return f
コード例 #2
0
 def test_open_args(self):
     self.deferred_open_file = DeferredOpenFile(
         self.filename, mode='ab+',
         open_function=self.recording_open_function)
     # Force an open
     self.deferred_open_file.write(b'data')
     self.assertEqual(len(self.open_call_args), 1)
     self.assertEqual(self.open_call_args[0], (self.filename, 'ab+'))
コード例 #3
0
 def setUp(self):
     super(TestDeferredOpenFile, self).setUp()
     self.filename = os.path.join(self.tempdir, 'foo')
     self.contents = b'my contents'
     with open(self.filename, 'wb') as f:
         f.write(self.contents)
     self.deferred_open_file = DeferredOpenFile(
         self.filename, open_function=self.recording_open_function)
     self.open_call_args = []
コード例 #4
0
    def test_open_seeks_with_nonzero_start_byte(self):
        self.deferred_open_file = DeferredOpenFile(
            self.filename, mode='wb', start_byte=5,
            open_function=self.open_nonseekable)

        # Since a non-seekable file is being opened, calling Seek will raise
        # an UnsupportedOperation error.
        with self.assertRaises(io.UnsupportedOperation):
            self.deferred_open_file.write(b'data')
コード例 #5
0
ファイル: test_utils.py プロジェクト: pisymbol/s3transfer
 def setUp(self):
     super(TestDefferedOpenFile, self).setUp()
     self.filename = os.path.join(self.tempdir, 'foo')
     self.contents = b'my contents'
     with open(self.filename, 'wb') as f:
         f.write(self.contents)
     self.deferred_open_file = DeferredOpenFile(self.filename)
     self.open_called_count = 0
     self.deferred_open_file.OPEN_METHOD = self.counting_open_method
コード例 #6
0
    def test_open_does_not_seek_with_zero_start_byte(self):
        self.deferred_open_file = DeferredOpenFile(
            self.filename, mode='wb', start_byte=0,
            open_function=self.open_nonseekable)

        try:
            # If this seeks, an UnsupportedOperation error will be raised.
            self.deferred_open_file.write(b'data')
        except io.UnsupportedOperation:
            self.fail('DeferredOpenFile seeked upon opening')
コード例 #7
0
    def test_write(self):
        self.deferred_open_file = DeferredOpenFile(
            self.filename, mode='wb',
            open_function=self.recording_open_function)

        write_content = b'foo'
        self.deferred_open_file.write(write_content)
        self.deferred_open_file.write(write_content)
        self.deferred_open_file.close()
        # Both of the writes should now be in the file.
        with open(self.filename, 'rb') as f:
            self.assertEqual(f.read(), write_content*2)
        # Open should have only been called once.
        self.assertEqual(len(self.open_call_args), 1)
コード例 #8
0
 def _get_deferred_open_file(self, fileobj, start_byte):
     fileobj = DeferredOpenFile(fileobj, start_byte)
     fileobj.OPEN_METHOD = self._osutil.open
     return fileobj
コード例 #9
0
 def _get_deferred_open_file(self, fileobj, start_byte):
     fileobj = DeferredOpenFile(
         fileobj, start_byte, open_function=self._osutil.open)
     return fileobj
コード例 #10
0
 def test_instantiation_does_not_open_file(self):
     DeferredOpenFile(self.filename,
                      open_function=self.recording_open_function)
     self.assertEqual(len(self.open_call_args), 0)
コード例 #11
0
ファイル: test_utils.py プロジェクト: pisymbol/s3transfer
 def test_instantiation_does_not_open_file(self):
     deferred_open_file = DeferredOpenFile(self.filename)
     self.open_called_count = 0
     deferred_open_file.OPEN_METHOD = self.counting_open_method
     self.assertEqual(self.open_called_count, 0)