1
0
mirror of https://github.com/nvbn/thefuck.git synced 2024-10-06 10:51:11 +01:00
thefuck/tests/rules/test_no_command.py

46 lines
1.7 KiB
Python
Raw Normal View History

2015-04-08 18:00:03 +01:00
from subprocess import PIPE
2015-04-17 15:24:03 +01:00
from mock import patch, Mock
import pytest
2015-04-08 18:00:03 +01:00
from thefuck.rules.no_command import match, get_new_command
from thefuck.main import Command
@pytest.fixture
def command_found():
return b'''No command 'aptget' found, did you mean:
Command 'apt-get' from package 'apt' (main)
aptget: command not found
'''
@pytest.fixture
def command_not_found():
return b'''No command 'vom' found, but there are 19 similar ones
vom: command not found
'''
def test_match(command_found, command_not_found):
with patch('thefuck.rules.no_command.Popen') as Popen:
Popen.return_value.stderr.read.return_value = command_found
2015-04-08 20:08:35 +01:00
assert match(Command('aptget install vim', '', ''), None)
2015-04-08 18:00:03 +01:00
Popen.assert_called_once_with('/usr/lib/command-not-found aptget',
shell=True, stderr=PIPE)
Popen.return_value.stderr.read.return_value = command_not_found
2015-04-08 20:08:35 +01:00
assert not match(Command('ls', '', ''), None)
2015-04-08 18:00:03 +01:00
with patch('thefuck.rules.no_command.Popen') as Popen:
Popen.return_value.stderr.read.return_value = command_found
2015-04-08 20:08:35 +01:00
assert match(Command('sudo aptget install vim', '', ''),
Mock(command_not_found='test'))
Popen.assert_called_once_with('test aptget',
2015-04-08 18:00:03 +01:00
shell=True, stderr=PIPE)
def test_get_new_command(command_found):
with patch('thefuck.rules.no_command._get_output',
return_value=command_found.decode()):
2015-04-08 20:08:35 +01:00
assert get_new_command(Command('aptget install vim', '', ''), None)\
2015-04-08 18:00:03 +01:00
== 'apt-get install vim'
2015-04-08 20:08:35 +01:00
assert get_new_command(Command('sudo aptget install vim', '', ''), None) \
2015-04-08 18:00:03 +01:00
== 'sudo apt-get install vim'