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

Add tests

This commit is contained in:
gkodosis 2020-06-30 20:11:23 +03:00
parent 31a594debc
commit fec207483d
3 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,51 @@
import pytest
from thefuck.rules.goenv_no_such_command import get_new_command, match
from thefuck.types import Command
@pytest.fixture
def output(goenv_cmd):
return "goenv: no such command '{}'".format(goenv_cmd)
@pytest.fixture(autouse=True)
def Popen(mocker):
mock = mocker.patch('thefuck.rules.goenv_no_such_command.Popen')
mock.return_value.stdout.readlines.return_value = (
b'--version\nactivate\ncommands\ncompletions\ndeactivate\ndoctor_\n'
b'exec\nglobal\nhelp\nhooks\ninit\ninstall\ninstaller\nlocal\noffline-installer_\n'
b'prefix\nrealpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nupdate_\n'
b'version\nversion-file\nversion-file-read\nversion-file-write\nversion-name_\n'
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs\nwhence\nwhich_\n'
).split()
return mock
@pytest.mark.parametrize('script, goenv_cmd', [
('goenv globe', 'globe'),
('goenv intall 1.4.0', 'intall'),
('goenv list', 'list'),
])
def test_match(script, goenv_cmd, output):
assert match(Command(script, output=output))
@pytest.mark.parametrize('script, output', [
('goenv global', 'system'),
('goenv versions', ' 1.5.0\n 1.5.1\n* 1.5.2\n'),
('goenv install --list', ' 1.5.0\n 1.5.1\n 1.5.2\n'),
])
def test_not_match(script, output):
assert not match(Command(script, output=output))
@pytest.mark.parametrize('script, goenv_cmd, result', [
('goenv globe', 'globe', 'goenv global'),
('goenv intall 1.4.0', 'intall', 'goenv install 1.4.0'),
('goenv list', 'list', 'goenv install --list'),
('goenv remove 1.4.0', 'remove', 'goenv uninstall 1.4.0'),
])
def test_get_new_command(script, goenv_cmd, output, result):
assert result in get_new_command(Command(script, output))

View File

@ -0,0 +1,52 @@
import pytest
from thefuck.rules.nodenv_no_such_command import get_new_command, match
from thefuck.types import Command
@pytest.fixture
def output(nodenv_cmd):
return "nodenv: no such command `{}'".format(nodenv_cmd)
@pytest.fixture(autouse=True)
def Popen(mocker):
mock = mocker.patch('thefuck.rules.nodenv_no_such_command.Popen')
mock.return_value.stdout.readlines.return_value = (
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
).split()
return mock
@pytest.mark.parametrize('script, nodenv_cmd', [
('nodenv globe', 'globe'),
('nodenv intall 3.8.0', 'intall'),
('nodenv list', 'list'),
])
def test_match(script, nodenv_cmd, output):
assert match(Command(script, output=output))
@pytest.mark.parametrize('script, output', [
('nodenv global', 'system'),
('nodenv versions', ' 3.7.0\n 3.7.1\n* 3.7.2\n'),
('nodenv install --list', ' 3.7.0\n 3.7.1\n 3.7.2\n'),
])
def test_not_match(script, output):
assert not match(Command(script, output=output))
@pytest.mark.parametrize('script, nodenv_cmd, result', [
('nodenv globe', 'globe', 'nodenv global'),
('nodenv intall 3.8.0', 'intall', 'nodenv install 3.8.0'),
('nodenv list', 'list', 'nodenv install --list'),
('nodenv remove 3.8.0', 'remove', 'nodenv uninstall 3.8.0'),
])
def test_get_new_command(script, nodenv_cmd, output, result):
assert result in get_new_command(Command(script, output))

View File

@ -0,0 +1,52 @@
import pytest
from thefuck.rules.rbenv_no_such_command import get_new_command, match
from thefuck.types import Command
@pytest.fixture
def output(rbenv_cmd):
return "rbenv: no such command `{}'".format(rbenv_cmd)
@pytest.fixture(autouse=True)
def Popen(mocker):
mock = mocker.patch('thefuck.rules.rbenv_no_such_command.Popen')
mock.return_value.stdout.readlines.return_value = (
b'--version\nactivate\ncommands\ncompletions\ndeactivate\nexec_\n'
b'global\nhelp\nhooks\ninit\ninstall\nlocal\nprefix_\n'
b'realpath.dylib\nrehash\nroot\nshell\nshims\nuninstall\nversion_\n'
b'version-file\nversion-file-read\nversion-file-write\nversion-name_\n'
b'version-origin\nversions\nvirtualenv\nvirtualenv-delete_\n'
b'virtualenv-init\nvirtualenv-prefix\nvirtualenvs_\n'
b'virtualenvwrapper\nvirtualenvwrapper_lazy\nwhence\nwhich_\n'
).split()
return mock
@pytest.mark.parametrize('script, rbenv_cmd', [
('rbenv globe', 'globe'),
('rbenv intall 3.8.0', 'intall'),
('rbenv list', 'list'),
])
def test_match(script, rbenv_cmd, output):
assert match(Command(script, output=output))
@pytest.mark.parametrize('script, output', [
('rbenv global', 'system'),
('rbenv versions', ' 3.7.0\n 3.7.1\n* 3.7.2\n'),
('rbenv install --list', ' 3.7.0\n 3.7.1\n 3.7.2\n'),
])
def test_not_match(script, output):
assert not match(Command(script, output=output))
@pytest.mark.parametrize('script, rbenv_cmd, result', [
('rbenv globe', 'globe', 'rbenv global'),
('rbenv intall 3.8.0', 'intall', 'rbenv install 3.8.0'),
('rbenv list', 'list', 'rbenv install --list'),
('rbenv remove 3.8.0', 'remove', 'rbenv uninstall 3.8.0'),
])
def test_get_new_command(script, rbenv_cmd, output, result):
assert result in get_new_command(Command(script, output))