mirror of
https://github.com/nvbn/thefuck.git
synced 2025-10-30 14:44:05 +00:00
#102 Use side_effect in ssh_known_host rule
This commit is contained in:
@@ -2,7 +2,7 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
from thefuck.rules.ssh_known_hosts import match, get_new_command,\
|
from thefuck.rules.ssh_known_hosts import match, get_new_command,\
|
||||||
remove_offending_keys
|
side_effect
|
||||||
from tests.utils import Command
|
from tests.utils import Command
|
||||||
|
|
||||||
|
|
||||||
@@ -53,18 +53,14 @@ def test_match(ssh_error):
|
|||||||
assert not match(Command('ssh'), None)
|
assert not match(Command('ssh'), None)
|
||||||
|
|
||||||
|
|
||||||
def test_remove_offending_keys(ssh_error):
|
def test_side_effect(ssh_error):
|
||||||
errormsg, path, reset, known_hosts = ssh_error
|
errormsg, path, reset, known_hosts = ssh_error
|
||||||
command = Command('ssh user@host', stderr=errormsg)
|
command = Command('ssh user@host', stderr=errormsg)
|
||||||
remove_offending_keys(command, None)
|
side_effect(command, None)
|
||||||
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
|
expected = ['123.234.567.890 asdjkasjdakjsd\n', '111.222.333.444 qwepoiwqepoiss\n']
|
||||||
assert known_hosts(path) == expected
|
assert known_hosts(path) == expected
|
||||||
|
|
||||||
|
|
||||||
def test_get_new_command(ssh_error, monkeypatch):
|
def test_get_new_command(ssh_error, monkeypatch):
|
||||||
errormsg, _, _, _ = ssh_error
|
errormsg, _, _, _ = ssh_error
|
||||||
|
|
||||||
method = Mock()
|
|
||||||
monkeypatch.setattr('thefuck.rules.ssh_known_hosts.remove_offending_keys', method)
|
|
||||||
assert get_new_command(Command('ssh user@host', stderr=errormsg), None) == 'ssh user@host'
|
assert get_new_command(Command('ssh user@host', stderr=errormsg), None) == 'ssh user@host'
|
||||||
assert method.call_count
|
|
||||||
|
|||||||
@@ -22,7 +22,11 @@ def match(command, settings):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def remove_offending_keys(command, settings):
|
def get_new_command(command, settings):
|
||||||
|
return command.script
|
||||||
|
|
||||||
|
|
||||||
|
def side_effect(command, settings):
|
||||||
offending = offending_pattern.findall(command.stderr)
|
offending = offending_pattern.findall(command.stderr)
|
||||||
for filepath, lineno in offending:
|
for filepath, lineno in offending:
|
||||||
with open(filepath, 'r') as fh:
|
with open(filepath, 'r') as fh:
|
||||||
@@ -30,8 +34,3 @@ def remove_offending_keys(command, settings):
|
|||||||
del lines[int(lineno) - 1]
|
del lines[int(lineno) - 1]
|
||||||
with open(filepath, 'w') as fh:
|
with open(filepath, 'w') as fh:
|
||||||
fh.writelines(lines)
|
fh.writelines(lines)
|
||||||
|
|
||||||
|
|
||||||
def get_new_command(command, settings):
|
|
||||||
remove_offending_keys(command, settings)
|
|
||||||
return command.script
|
|
||||||
|
|||||||
Reference in New Issue
Block a user