mirror of
https://github.com/nvbn/thefuck.git
synced 2025-10-29 22:24:44 +00:00
Add useful constructors for Rule and Command for tests
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import os
|
||||
import pytest
|
||||
from mock import Mock
|
||||
from thefuck.types import Command
|
||||
from thefuck.rules.ssh_known_hosts import match, get_new_command, remove_offending_keys
|
||||
from thefuck.rules.ssh_known_hosts import match, get_new_command,\
|
||||
remove_offending_keys
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -43,18 +44,18 @@ Host key verification failed.""".format(path, '98.765.432.321')
|
||||
|
||||
def test_match(ssh_error):
|
||||
errormsg, _, _, _ = ssh_error
|
||||
assert match(Command('ssh', '', errormsg), None)
|
||||
assert match(Command('ssh', '', errormsg), None)
|
||||
assert match(Command('scp something something', '', errormsg), None)
|
||||
assert match(Command('scp something something', '', errormsg), None)
|
||||
assert not match(Command('', '', errormsg), None)
|
||||
assert not match(Command('notssh', '', errormsg), None)
|
||||
assert not match(Command('ssh', '', ''), None)
|
||||
assert match(Command('ssh', stderr=errormsg), None)
|
||||
assert match(Command('ssh', stderr=errormsg), None)
|
||||
assert match(Command('scp something something', stderr=errormsg), None)
|
||||
assert match(Command('scp something something', stderr=errormsg), None)
|
||||
assert not match(Command(stderr=errormsg), None)
|
||||
assert not match(Command('notssh', stderr=errormsg), None)
|
||||
assert not match(Command('ssh'), None)
|
||||
|
||||
|
||||
def test_remove_offending_keys(ssh_error):
|
||||
errormsg, path, reset, known_hosts = ssh_error
|
||||
command = Command('ssh user@host', '', errormsg)
|
||||
command = Command('ssh user@host', stderr=errormsg)
|
||||
remove_offending_keys(command, None)
|
||||
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
|
||||
assert known_hosts(path) == expected
|
||||
@@ -65,5 +66,5 @@ def test_get_new_command(ssh_error, monkeypatch):
|
||||
|
||||
method = Mock()
|
||||
monkeypatch.setattr('thefuck.rules.ssh_known_hosts.remove_offending_keys', method)
|
||||
assert get_new_command(Command('ssh user@host', '', errormsg), None) == 'ssh user@host'
|
||||
assert get_new_command(Command('ssh user@host', stderr=errormsg), None) == 'ssh user@host'
|
||||
assert method.call_count
|
||||
|
||||
Reference in New Issue
Block a user