1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-14 14:48:49 +00:00

Use output as test fixture

This commit is contained in:
David 2018-01-03 21:20:22 +00:00
parent 85e240e7d1
commit 3c0cba290c

View File

@ -3,52 +3,55 @@ from thefuck.rules.git_push import match, get_new_command
from thefuck.types import Command
@pytest.fixture
def output(branch):
return '''fatal: The current branch {} has no upstream branch.
To push the current branch and set the remote as upstream, use
@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 {}
git push --set-upstream origin {}
'''.format(branch, branch)
'''.format(request.param, request.param)
@pytest.mark.parametrize('command', [
Command('git push', output('master')),
Command('git push master', output('master'))])
def test_match(command):
assert match(command)
@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('command', [
Command('git push master', ''),
Command('ls', output('master'))])
def test_not_match(command):
assert not match(command)
@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('command, new_command', [
(Command('git push master', output('master')),
@pytest.mark.parametrize('script, output, new_command', [
('git push master', 'master',
'git push --set-upstream origin master'),
(Command('git push master', output('master')),
('git push master', 'master',
'git push --set-upstream origin master'),
(Command('git push master', output('master')),
('git push master', 'master',
'git push --set-upstream origin master'),
(Command('git push -u', output('master')),
('git push -u', 'master',
'git push --set-upstream origin master'),
(Command('git push -u origin', output('master')),
('git push -u origin', 'master',
'git push --set-upstream origin master'),
(Command('git push origin', output('master')),
('git push origin', 'master',
'git push --set-upstream origin master'),
(Command('git push --set-upstream origin', output('master')),
('git push --set-upstream origin', 'master',
'git push --set-upstream origin master'),
(Command('git push --quiet', output('master')),
('git push --quiet', 'master',
'git push --set-upstream origin master --quiet'),
(Command('git push --quiet origin', output('master')),
('git push --quiet origin', 'master',
'git push --set-upstream origin master --quiet'),
(Command('git -c test=test push --quiet origin', output('master')),
('git -c test=test push --quiet origin', 'master',
'git -c test=test push --set-upstream origin master --quiet'),
(Command('git push', output("test's")),
"git push --set-upstream origin test\\'s")])
def test_get_new_command(command, new_command):
assert get_new_command(command) == new_command
('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