2015-04-08 18:15:49 +02:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.git_push import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2015-04-08 18:15:49 +02:00
|
|
|
|
|
|
|
|
2018-01-03 21:20:22 +00:00
|
|
|
@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
|
2015-04-08 18:15:49 +02:00
|
|
|
|
2018-01-03 21:20:22 +00:00
|
|
|
git push --set-upstream origin {}
|
2018-01-02 23:17:19 +00:00
|
|
|
|
2018-01-03 21:20:22 +00:00
|
|
|
'''.format(request.param, request.param)
|
2018-01-02 23:17:19 +00:00
|
|
|
|
|
|
|
|
2018-01-03 21:20:22 +00:00
|
|
|
@pytest.mark.parametrize('script, output', [
|
|
|
|
('git push', 'master'),
|
|
|
|
('git push origin', 'master')], indirect=['output'])
|
|
|
|
def test_match(script, output):
|
|
|
|
assert match(Command(script, output))
|
2018-01-02 23:17:19 +00:00
|
|
|
|
|
|
|
|
2018-01-03 21:20:22 +00:00
|
|
|
@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))
|
2018-01-02 23:17:19 +00:00
|
|
|
|
|
|
|
|
2018-01-03 21:20:22 +00:00
|
|
|
@pytest.mark.parametrize('script, output, new_command', [
|
|
|
|
('git push master', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push master', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push master', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push -u', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push -u origin', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push origin', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push --set-upstream origin', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push --quiet', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master --quiet'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git push --quiet origin', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git push --set-upstream origin master --quiet'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('git -c test=test push --quiet origin', 'master',
|
2018-01-02 23:17:19 +00:00
|
|
|
'git -c test=test push --set-upstream origin master --quiet'),
|
2018-01-03 21:20:22 +00:00
|
|
|
('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
|