1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-20 01:28:56 +00:00
thefuck/tests/rules/test_git_push.py
2018-01-03 21:20:22 +00:00

58 lines
2.0 KiB
Python

import pytest
from thefuck.rules.git_push import match, get_new_command
from thefuck.types import Command
@pytest.fixture(scope='function')
def output(request):
if not request.param:
return ''
else:
return '''fatal: The current branch {} has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin {}
'''.format(request.param, request.param)
@pytest.mark.parametrize('script, output', [
('git push', 'master'),
('git push origin', 'master')], indirect=['output'])
def test_match(script, output):
assert match(Command(script, output))
@pytest.mark.parametrize('script, output', [
('git push master', None),
('ls', 'master')], indirect=['output'])
def test_not_match(script, output):
assert not match(Command(script, output))
@pytest.mark.parametrize('script, output, new_command', [
('git push master', 'master',
'git push --set-upstream origin master'),
('git push master', 'master',
'git push --set-upstream origin master'),
('git push master', 'master',
'git push --set-upstream origin master'),
('git push -u', 'master',
'git push --set-upstream origin master'),
('git push -u origin', 'master',
'git push --set-upstream origin master'),
('git push origin', 'master',
'git push --set-upstream origin master'),
('git push --set-upstream origin', 'master',
'git push --set-upstream origin master'),
('git push --quiet', 'master',
'git push --set-upstream origin master --quiet'),
('git push --quiet origin', 'master',
'git push --set-upstream origin master --quiet'),
('git -c test=test push --quiet origin', 'master',
'git -c test=test push --set-upstream origin master --quiet'),
('git push', "test's",
"git push --set-upstream origin test\\'s")], indirect=['output'])
def test_get_new_command(script, output, new_command):
assert get_new_command(Command(script, output)) == new_command