mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-30 22:54:14 +00:00 
			
		
		
		
	#82 Remove unned print, fix python 3 support
This commit is contained in:
		| @@ -1,5 +1,6 @@ | |||||||
| import os | import os | ||||||
| import pytest | import pytest | ||||||
|  | from mock import Mock | ||||||
| from thefuck.main import Command | from thefuck.main 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 | ||||||
|  |  | ||||||
| @@ -55,20 +56,14 @@ def test_remove_offending_keys(ssh_error): | |||||||
|     errormsg, path, reset, known_hosts = ssh_error |     errormsg, path, reset, known_hosts = ssh_error | ||||||
|     command = Command('ssh user@host', '', errormsg) |     command = Command('ssh user@host', '', errormsg) | ||||||
|     remove_offending_keys(command, None) |     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 |     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 | ||||||
|  |  | ||||||
|     class Mock: |  | ||||||
|         was_called = False |  | ||||||
|  |  | ||||||
|         def __call__(self, *args, **kwargs): |  | ||||||
|             self.was_called = True |  | ||||||
|  |  | ||||||
|     method = Mock() |     method = Mock() | ||||||
|     monkeypatch.setattr('thefuck.rules.ssh_known_hosts.remove_offending_keys', method) |     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', '', errormsg), None) == 'ssh user@host' | ||||||
|     assert method.was_called |     assert method.call_count | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| import re | import re | ||||||
|  |  | ||||||
| patterns = [ | patterns = [ | ||||||
|     r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!', |     r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!', | ||||||
|     r'WARNING: POSSIBLE DNS SPOOFING DETECTED!', |     r'WARNING: POSSIBLE DNS SPOOFING DETECTED!', | ||||||
| @@ -23,12 +24,10 @@ def match(command, settings): | |||||||
|  |  | ||||||
| def remove_offending_keys(command, settings): | def remove_offending_keys(command, settings): | ||||||
|     offending = offending_pattern.findall(command.stderr) |     offending = offending_pattern.findall(command.stderr) | ||||||
|     print offending |  | ||||||
|     for filepath, lineno in offending: |     for filepath, lineno in offending: | ||||||
|         with open(filepath, 'r') as fh: |         with open(filepath, 'r') as fh: | ||||||
|             lines = fh.readlines() |             lines = fh.readlines() | ||||||
|             del lines[int(lineno) - 1] |             del lines[int(lineno) - 1] | ||||||
|             print lines |  | ||||||
|         with open(filepath, 'w') as fh: |         with open(filepath, 'w') as fh: | ||||||
|             fh.writelines(lines) |             fh.writelines(lines) | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user