2016-06-28 03:00:00 +03:00
|
|
|
import pytest
|
|
|
|
from thefuck.rules.ln_s_order import match, get_new_command
|
2017-08-31 17:58:56 +02:00
|
|
|
from thefuck.types import Command
|
2016-06-28 03:00:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def file_exists(mocker):
|
|
|
|
return mocker.patch('os.path.exists', return_value=True)
|
|
|
|
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
get_output = "ln: failed to create symbolic link '{}': File exists".format
|
2016-06-28 03:00:00 +03:00
|
|
|
|
|
|
|
|
2017-08-31 17:58:56 +02:00
|
|
|
@pytest.mark.parametrize('script, output, exists', [
|
|
|
|
('ln dest source', get_output('source'), True),
|
|
|
|
('ls -s dest source', get_output('source'), True),
|
2016-06-28 03:00:00 +03:00
|
|
|
('ln -s dest source', '', True),
|
2017-08-31 17:58:56 +02:00
|
|
|
('ln -s dest source', get_output('source'), False)])
|
|
|
|
def test_not_match(file_exists, script, output, exists):
|
2016-06-28 03:00:00 +03:00
|
|
|
file_exists.return_value = exists
|
2017-08-31 17:58:56 +02:00
|
|
|
assert not match(Command(script, output))
|
2016-06-28 03:00:00 +03:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures('file_exists')
|
|
|
|
@pytest.mark.parametrize('script, result', [
|
|
|
|
('ln -s dest source', 'ln -s source dest'),
|
|
|
|
('ln dest -s source', 'ln -s source dest'),
|
|
|
|
('ln dest source -s', 'ln source -s dest')])
|
|
|
|
def test_match(script, result):
|
2017-08-31 17:58:56 +02:00
|
|
|
output = get_output('source')
|
|
|
|
assert match(Command(script, output))
|
|
|
|
assert get_new_command(Command(script, output)) == result
|