def test_exceptions_get_raised(self, monkeypatch): mock_sp_call = mock.Mock(return_value=7) monkeypatch.setattr(utils.subprocess, 'call', mock_sp_call) path = 'foo/bar/baz' args = ['par2', 'c', '-r5', 'baz.par2', path] with pytest.raises(exceptions.ParchiveError) as e: utils.create_parity_files(path) assert e.value == '{0} failed with code {1}'.format(' '.join(args), 7) with open(os.devnull, 'wb') as DEVNULL: mock_sp_call.assert_called_once_with(args, stdout=DEVNULL, stderr=DEVNULL)
def test_exceptions_get_raised(self, monkeypatch): mock_sp_call = mock.Mock(return_value=7) monkeypatch.setattr(utils.subprocess, 'call', mock_sp_call) path = 'foo/bar/baz' args = ['par2', 'c', '-r5', 'baz.par2', path] with pytest.raises(exceptions.ParchiveError) as e: utils.create_parity_files(path) assert e.value == '{0} failed with code {1}'.format(' '.join(args), 7) with open(os.devnull, 'wb') as DEVNULL: mock_sp_call.assert_called_once_with(args, stdout=DEVNULL, stderr=DEVNULL)
def _parity_create_files(self, name, credentials, settings): path = os.path.join(osf_settings.FILE_PATH_COMPLETE, name) loop = asyncio.get_event_loop() with utils.RetryUpload(self): parity_paths = utils.create_parity_files( path, redundancy=osf_settings.PARITY_REDUNDANCY, ) futures = [asyncio.async(_upload_parity(each, credentials, settings)) for each in parity_paths]
def test_skip_empty_files(self, monkeypatch): mock_stat = mock.Mock(return_value=mock.Mock(st_size=0)) mock_sp_call = mock.Mock() monkeypatch.setattr(os, 'stat', mock_stat) monkeypatch.setattr(utils.subprocess, 'call', mock_sp_call) path = 'foo/bar/baz' paths = utils.create_parity_files(path) assert paths == [] assert not mock_sp_call.called
def test_skip_empty_files(self, monkeypatch): mock_stat = mock.Mock(return_value=mock.Mock(st_size=0)) mock_sp_call = mock.Mock() monkeypatch.setattr(os, 'stat', mock_stat) monkeypatch.setattr(utils.subprocess, 'call', mock_sp_call) path = 'foo/bar/baz' paths = utils.create_parity_files(path) assert paths == [] assert not mock_sp_call.called
def _parity_create_files(self, name, credentials, settings): path = os.path.join(osf_settings.FILE_PATH_COMPLETE, name) loop = asyncio.get_event_loop() with utils.RetryUpload(self): parity_paths = utils.create_parity_files( path, redundancy=osf_settings.PARITY_REDUNDANCY, ) if not parity_paths: #create_parity_files will return [] for empty files return futures = [asyncio.async(_upload_parity(each, credentials, settings)) for each in parity_paths]