1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-21 20:38:54 +00:00

#102 Use side_effect in ssh_known_host rule

This commit is contained in:
nvbn 2015-05-01 04:41:33 +02:00
parent b985dfbffc
commit 5eeb9d704c
2 changed files with 8 additions and 13 deletions

View File

@ -2,7 +2,7 @@ import os
import pytest
from mock import Mock
from thefuck.rules.ssh_known_hosts import match, get_new_command,\
remove_offending_keys
side_effect
from tests.utils import Command
@ -53,18 +53,14 @@ def test_match(ssh_error):
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
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']
assert known_hosts(path) == expected
def test_get_new_command(ssh_error, monkeypatch):
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 method.call_count

View File

@ -22,7 +22,11 @@ def match(command, settings):
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)
for filepath, lineno in offending:
with open(filepath, 'r') as fh:
@ -30,8 +34,3 @@ def remove_offending_keys(command, settings):
del lines[int(lineno) - 1]
with open(filepath, 'w') as fh:
fh.writelines(lines)
def get_new_command(command, settings):
remove_offending_keys(command, settings)
return command.script