mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-21 20:38:54 +00:00
Merge pull request #452 from scorphus/increase-coverage
Increase coverage
This commit is contained in:
commit
c5acee54ea
@ -29,12 +29,27 @@ def test_match_mocked(cmdnf_mock, command, return_value):
|
|||||||
assert get_packages.called
|
assert get_packages.called
|
||||||
|
|
||||||
|
|
||||||
|
# python-commandnotfound is available in ubuntu 14.04+
|
||||||
|
@pytest.mark.skipif(not getattr(apt_get, 'enabled_by_default', True),
|
||||||
|
reason='Skip if python-commandnotfound is not available')
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
|
Command(script='a_bad_cmd', stderr='a_bad_cmd: command not found'),
|
||||||
Command(script='vim', stderr=''), Command()])
|
Command(script='vim', stderr=''), Command()])
|
||||||
def test_not_match(command):
|
def test_not_match(command):
|
||||||
assert not match(command)
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('command, return_value', [
|
||||||
|
(Command(script='a_bad_cmd', stderr='a_bad_cmd: command not found'), []),
|
||||||
|
(Command(script='vim', stderr=''), []), (Command(), [])])
|
||||||
|
@patch('thefuck.rules.apt_get.CommandNotFound', create=True)
|
||||||
|
@patch.multiple(apt_get, create=True, apt_get='apt_get')
|
||||||
|
def test_not_match_mocked(cmdnf_mock, command, return_value):
|
||||||
|
get_packages = Mock(return_value=return_value)
|
||||||
|
cmdnf_mock.CommandNotFound.return_value = Mock(getPackages=get_packages)
|
||||||
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
# python-commandnotfound is available in ubuntu 14.04+
|
# python-commandnotfound is available in ubuntu 14.04+
|
||||||
@pytest.mark.skipif(not getattr(apt_get, 'enabled_by_default', True),
|
@pytest.mark.skipif(not getattr(apt_get, 'enabled_by_default', True),
|
||||||
reason='Skip if python-commandnotfound is not available')
|
reason='Skip if python-commandnotfound is not available')
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import pytest
|
import pytest
|
||||||
from thefuck.rules.git_checkout import match, get_new_command
|
from io import BytesIO
|
||||||
|
from thefuck.rules.git_checkout import match, get_branches, get_new_command
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
@ -13,8 +14,10 @@ def did_not_match(target, did_you_forget=False):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def get_branches(mocker):
|
def git_branch(mocker, branches):
|
||||||
return mocker.patch('thefuck.rules.git_checkout.get_branches')
|
mock = mocker.patch('subprocess.Popen')
|
||||||
|
mock.return_value.stdout = BytesIO(branches)
|
||||||
|
return mock
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('command', [
|
@pytest.mark.parametrize('command', [
|
||||||
@ -33,21 +36,34 @@ def test_not_match(command):
|
|||||||
assert not match(command)
|
assert not match(command)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('branches, branch_list', [
|
||||||
|
(b'', []),
|
||||||
|
(b'* master', ['master']),
|
||||||
|
(b' remotes/origin/master', ['master']),
|
||||||
|
(b' just-another-branch', ['just-another-branch']),
|
||||||
|
(b'* master\n just-another-branch', ['master', 'just-another-branch']),
|
||||||
|
(b'* master\n remotes/origin/master\n just-another-branch',
|
||||||
|
['master', 'master', 'just-another-branch'])])
|
||||||
|
def test_get_branches(branches, branch_list, git_branch):
|
||||||
|
git_branch(branches)
|
||||||
|
assert list(get_branches()) == branch_list
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('branches, command, new_command', [
|
@pytest.mark.parametrize('branches, command, new_command', [
|
||||||
([],
|
(b'',
|
||||||
Command(script='git checkout unknown', stderr=did_not_match('unknown')),
|
Command(script='git checkout unknown', stderr=did_not_match('unknown')),
|
||||||
'git branch unknown && git checkout unknown'),
|
'git branch unknown && git checkout unknown'),
|
||||||
([],
|
(b'',
|
||||||
Command('git commit unknown', stderr=did_not_match('unknown')),
|
Command('git commit unknown', stderr=did_not_match('unknown')),
|
||||||
'git branch unknown && git commit unknown'),
|
'git branch unknown && git commit unknown'),
|
||||||
(['test-random-branch-123'],
|
(b' test-random-branch-123',
|
||||||
Command(script='git checkout tst-rdm-brnch-123',
|
Command(script='git checkout tst-rdm-brnch-123',
|
||||||
stderr=did_not_match('tst-rdm-brnch-123')),
|
stderr=did_not_match('tst-rdm-brnch-123')),
|
||||||
'git checkout test-random-branch-123'),
|
'git checkout test-random-branch-123'),
|
||||||
(['test-random-branch-123'],
|
(b' test-random-branch-123',
|
||||||
Command(script='git commit tst-rdm-brnch-123',
|
Command(script='git commit tst-rdm-brnch-123',
|
||||||
stderr=did_not_match('tst-rdm-brnch-123')),
|
stderr=did_not_match('tst-rdm-brnch-123')),
|
||||||
'git commit test-random-branch-123')])
|
'git commit test-random-branch-123')])
|
||||||
def test_get_new_command(branches, command, new_command, get_branches):
|
def test_get_new_command(branches, command, new_command, git_branch):
|
||||||
get_branches.return_value = branches
|
git_branch(branches)
|
||||||
assert get_new_command(command) == new_command
|
assert get_new_command(command) == new_command
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
from io import BytesIO
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
from thefuck.rules.gulp_not_task import match, get_new_command
|
from thefuck.rules.gulp_not_task import match, get_new_command
|
||||||
|
|
||||||
@ -22,7 +23,7 @@ def test_not_march(script, stdout):
|
|||||||
|
|
||||||
|
|
||||||
def test_get_new_command(mocker):
|
def test_get_new_command(mocker):
|
||||||
mocker.patch('thefuck.rules.gulp_not_task.get_gulp_tasks', return_value=[
|
mock = mocker.patch('subprocess.Popen')
|
||||||
'serve', 'build', 'default'])
|
mock.return_value.stdout = BytesIO(b'serve \nbuild \ndefault \n')
|
||||||
command = Command('gulp srve', stdout('srve'))
|
command = Command('gulp srve', stdout('srve'))
|
||||||
assert get_new_command(command) == ['gulp serve', 'gulp default']
|
assert get_new_command(command) == ['gulp serve', 'gulp default']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user