def test_restash_untrackedFiles(self, mock_info, mock_call, mock_parents, mock_callinput, mock_checkoutput, mock_isvalidstash): # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' untracked_files = ['file1', 'file2'] mock_checkoutput.side_effect = [ 'stash1', reverse_patch_output, '\n'.join(untracked_files), stash_sha + '\n' ] mock_callinput.return_value = 0 # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git ls-tree --name-only stash@{0}^3'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_callinput.assert_called_once_with(['git', 'apply', '--reverse'], reverse_patch_output) mock_parents.assert_called_once_with('stash@{0}') mock_call.assert_called_once_with( ['git', 'clean', '--force', '--quiet', '--'] + untracked_files) mock_info.assert_called_once_with( 'Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_untrackedFiles_butNoneFound(self, mock_info, mock_call, mock_parents, mock_callinput, mock_checkoutput, mock_isvalidstash): """This case is possible if --include-untracked is used when not needed.""" # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' mock_checkoutput.side_effect = [ 'stash1', reverse_patch_output, '', stash_sha + '\n' ] mock_callinput.return_value = 0 # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git ls-tree --name-only stash@{0}^3'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_callinput.assert_called_once_with(['git', 'apply', '--reverse'], reverse_patch_output) mock_parents.assert_called_once_with('stash@{0}') mock_call.assert_not_called() mock_info.assert_called_once_with( 'Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_unableToReverseApplyPath(self, mock_error, mock_callinput, mock_checkoutput, mock_isvaidstash): # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' mock_checkoutput.side_effect = [ 'stash1', reverse_patch_output, stash_sha + '\n' ] mock_callinput.return_value = 1 # when try: restash.restash() self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'), mock.call('git stash show --patch --no-color stash@{0}'.split()) ]) mock_callinput.assert_called_once_with(['git', 'apply', '--reverse'], reverse_patch_output) mock_error.assert_called_once_with('unable to reverse modifications', exit_=True)
def test_restash_noUntrackedFiles(self, mock_info, mock_parents, mock_callinput, mock_checkoutput, mock_isvalidstash): # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' mock_checkoutput.side_effect = [ 'stash1', reverse_patch_output, stash_sha + '\n' ] mock_callinput.return_value = 0 # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_callinput.assert_called_once_with(['git', 'apply', '--reverse'], reverse_patch_output) mock_parents.assert_called_once_with('stash@{0}') mock_info.assert_called_once_with( 'Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_untrackedFiles_butNoneFound(self, mock_info, mock_call, mock_parents, mock_popen, mock_checkoutput, mock_isvalidstash): """This case is possible if --include-untracked is used when not needed.""" # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' mock_checkoutput.side_effect = ['stash1', reverse_patch_output, '', stash_sha + '\n'] mock_process = mock.Mock() mock_process.returncode = 0 mock_popen.return_value = mock_process # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'.split()), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git ls-tree --name-only stash@{0}^3'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_popen.assert_called_once_with(['git', 'apply', '--reverse'], stdin=PIPE) mock_process.communicate.assert_called_once_with(input=reverse_patch_output) mock_parents.assert_called_once_with('stash@{0}') mock_call.assert_not_called() mock_info.assert_called_once_with('Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_untrackedFiles_noPatchToReverce(self, mock_info, mock_call, mock_parents, mock_callinput, mock_checkoutput, mock_isvalidstash): """This tests stashes consisting only of untracked files.""" # setup stash_sha = 'stash sha' untracked_files = ['file1', 'file2'] mock_checkoutput.side_effect = [ 'stash1', '', '\n'.join(untracked_files), stash_sha + '\n' ] # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git ls-tree --name-only stash@{0}^3'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_callinput.assert_not_called() mock_parents.assert_called_once_with('stash@{0}') mock_call.assert_called_once_with( ['git', 'clean', '--force', '--quiet', '--'] + untracked_files) mock_info.assert_called_once_with( 'Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_untrackedFiles(self, mock_info, mock_call, mock_parents, mock_popen, mock_checkoutput, mock_isvalidstash): # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' untracked_files = ['file1', 'file2'] mock_checkoutput.side_effect = ['stash1', reverse_patch_output, '\n'.join(untracked_files), stash_sha + '\n'] mock_process = mock.Mock() mock_process.returncode = 0 mock_popen.return_value = mock_process # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'.split()), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git ls-tree --name-only stash@{0}^3'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_popen.assert_called_once_with(['git', 'apply', '--reverse'], stdin=PIPE) mock_process.communicate.assert_called_once_with(input=reverse_patch_output) mock_parents.assert_called_once_with('stash@{0}') mock_call.assert_called_once_with(['git', 'clean', '--force', '--quiet', '--'] + untracked_files) mock_info.assert_called_once_with('Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_unableToReverseApplyPath(self, mock_error, mock_popen, mock_checkoutput, mock_isvaidstash): # setup reverse_patch_output = 'reverse patch' stash_sha = 'stash sha' mock_checkoutput.side_effect = ['stash1', reverse_patch_output, stash_sha + '\n'] mock_process = mock.Mock() mock_process.returncode = 1 mock_popen.return_value = mock_process # when try: restash.restash() self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'.split()), mock.call('git stash show --patch --no-color stash@{0}'.split()) ]) mock_popen.assert_called_once_with(['git', 'apply', '--reverse'], stdin=PIPE) mock_process.communicate.assert_called_once_with(input=reverse_patch_output) mock_error.assert_called_once_with('unable to reverse modifications', exit_=True)
def test_restash_untrackedFiles_noPatchToReverce(self, mock_info, mock_call, mock_parents, mock_popen, mock_checkoutput, mock_isvalidstash): """This tests stashes consisting only of untracked files.""" # setup stash_sha = 'stash sha' untracked_files = ['file1', 'file2'] mock_checkoutput.side_effect = ['stash1', '', '\n'.join(untracked_files), stash_sha + '\n'] mock_process = mock.Mock() mock_process.returncode = 0 mock_popen.return_value = mock_process # when restash.restash() # then mock_checkoutput.assert_has_calls([ mock.call('git stash list'.split()), mock.call('git stash show --patch --no-color stash@{0}'.split()), mock.call('git ls-tree --name-only stash@{0}^3'.split()), mock.call('git rev-parse stash@{0}'.split()) ]) mock_popen.assert_not_called() mock_parents.assert_called_once_with('stash@{0}') mock_call.assert_called_once_with(['git', 'clean', '--force', '--quiet', '--'] + untracked_files) mock_info.assert_called_once_with('Restashed stash@{{0}} ({})'.format(stash_sha), False)
def test_restash_noStashesExist(self, mock_error, mock_checkoutput): # when try: restash.restash() self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_checkoutput.assert_called_once_with('git stash list') mock_error.assert_called_once_with('no stashes exist')
def test_restash_noStashesExist(self, mock_error, mock_checkoutput): # when try: restash.restash() self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_checkoutput.assert_called_once_with('git stash list'.split()) mock_error.assert_called_once_with('no stashes exist')
def test_restash_invalidStash(self, mock_error, mock_isvalidstash, mock_checkoutput): # when stash = 'stash@{10}' try: restash.restash(stash) self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_checkoutput.assert_called_once_with('git stash list'.split()) mock_isvalidstash.assert_called_once_with(stash) mock_error.assert_called_once_with('{} is not a valid stash reference'.format(stash))
def test_restash_invalidStash(self, mock_error, mock_isvalidstash, mock_checkoutput): # when stash = 'stash@{10}' try: restash.restash(stash) self.fail('expected to exit but did not') # pragma: no cover except SystemExit: pass # then mock_checkoutput.assert_called_once_with('git stash list') mock_isvalidstash.assert_called_once_with(stash) mock_error.assert_called_once_with( '{} is not a valid stash reference'.format(stash))