def test_do_write_err(self): fd, tmpfile = mkstemp() try: fd1 = os.open(tmpfile, os.O_RDONLY) try: fs.do_write(fd1, "test") except SwiftOnFileSystemOSError: pass else: self.fail("SwiftOnFileSystemOSError expected") finally: os.close(fd1) except SwiftOnFileSystemOSError as ose: self.fail("Open failed with %s" % ose.strerror) finally: os.close(fd) os.remove(tmpfile)
def test_do_write(self): fd, tmpfile = mkstemp() try: cnt = fs.do_write(fd, "test") assert cnt == len("test") finally: os.close(fd) os.remove(tmpfile)
def _write_entire_chunk(self, chunk): bytes_per_sync = self._disk_file._mgr.bytes_per_sync while chunk: written = do_write(self._fd, chunk) chunk = chunk[written:] self._upload_size += written # For large files sync every 512MB (by default) written diff = self._upload_size - self._last_sync if diff >= bytes_per_sync: do_fsync(self._fd) self._last_sync = self._upload_size
def test_do_write_DiskFileNoSpace(self): def mock_os_write_enospc(fd, msg): raise OSError(errno.ENOSPC, os.strerror(errno.ENOSPC)) def mock_os_write_edquot(fd, msg): raise OSError(errno.EDQUOT, os.strerror(errno.EDQUOT)) with patch('os.write', mock_os_write_enospc): try: fs.do_write(9, "blah") except DiskFileNoSpace: pass else: self.fail("Expected DiskFileNoSpace exception") with patch('os.write', mock_os_write_edquot): try: fs.do_write(9, "blah") except DiskFileNoSpace: pass else: self.fail("Expected DiskFileNoSpace exception")