1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-20 09:39:01 +00:00
thefuck/tests/rules/test_git_push.py

57 lines
1.9 KiB
Python
Raw Normal View History

2015-04-08 18:15:49 +02:00
import pytest
from thefuck.rules.git_push import match, get_new_command
from thefuck.types import Command
2015-04-08 18:15:49 +02:00
@pytest.fixture
def output(branch_name):
if not branch_name:
2018-01-03 21:20:22 +00:00
return ''
2018-01-03 21:38:42 +00:00
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:38:42 +00:00
git push --set-upstream origin {}
2018-01-02 23:17:19 +00:00
'''.format(branch_name, branch_name)
2018-01-02 23:17:19 +00:00
@pytest.mark.parametrize('script, branch_name', [
2018-01-03 21:20:22 +00:00
('git push', 'master'),
('git push origin', 'master')])
def test_match(output, script, branch_name):
2018-01-03 21:20:22 +00:00
assert match(Command(script, output))
2018-01-02 23:17:19 +00:00
@pytest.mark.parametrize('script, branch_name', [
2018-01-03 21:20:22 +00:00
('git push master', None),
('ls', 'master')])
def test_not_match(output, script, branch_name):
2018-01-03 21:20:22 +00:00
assert not match(Command(script, output))
2018-01-02 23:17:19 +00:00
@pytest.mark.parametrize('script, branch_name, new_command', [
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 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")])
def test_get_new_command(output, script, branch_name, new_command):
2018-01-03 21:20:22 +00:00
assert get_new_command(Command(script, output)) == new_command