diff --git a/tests/rules/test_ssh_known_host.py b/tests/rules/test_ssh_known_host.py index 74a81469..9c8dc0d1 100644 --- a/tests/rules/test_ssh_known_host.py +++ b/tests/rules/test_ssh_known_host.py @@ -1,5 +1,6 @@ import os import pytest +from mock import Mock from thefuck.main import Command from thefuck.rules.ssh_known_hosts import match, get_new_command, remove_offending_keys @@ -41,7 +42,7 @@ Host key verification failed.""".format(path, '98.765.432.321') def test_match(ssh_error): - errormsg, _, _, _ = 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) @@ -55,20 +56,14 @@ def test_remove_offending_keys(ssh_error): errormsg, path, reset, known_hosts = ssh_error command = Command('ssh user@host', '', errormsg) remove_offending_keys(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 def test_get_new_command(ssh_error, monkeypatch): errormsg, _, _, _ = ssh_error - class Mock: - was_called = False - - def __call__(self, *args, **kwargs): - self.was_called = True - 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 method.was_called + assert method.call_count diff --git a/thefuck/rules/ssh_known_hosts.py b/thefuck/rules/ssh_known_hosts.py index 2f425bfe..ab73c422 100644 --- a/thefuck/rules/ssh_known_hosts.py +++ b/thefuck/rules/ssh_known_hosts.py @@ -1,4 +1,5 @@ import re + patterns = [ r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!', r'WARNING: POSSIBLE DNS SPOOFING DETECTED!', @@ -23,12 +24,10 @@ def match(command, settings): def remove_offending_keys(command, settings): offending = offending_pattern.findall(command.stderr) - print offending for filepath, lineno in offending: with open(filepath, 'r') as fh: lines = fh.readlines() del lines[int(lineno) - 1] - print lines with open(filepath, 'w') as fh: fh.writelines(lines)