2015-05-02 04:29:55 +02:00
|
|
|
import pytest
|
2015-04-08 18:15:49 +02:00
|
|
|
from subprocess import PIPE
|
2015-05-02 04:29:55 +02:00
|
|
|
from mock import Mock
|
2015-07-28 22:04:27 +03:00
|
|
|
from thefuck import main
|
|
|
|
from tests.utils import Command
|
2015-05-02 04:29:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestGetCommand(object):
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def Popen(self, monkeypatch):
|
|
|
|
Popen = Mock()
|
2015-04-08 18:15:49 +02:00
|
|
|
Popen.return_value.stdout.read.return_value = b'stdout'
|
|
|
|
Popen.return_value.stderr.read.return_value = b'stderr'
|
2015-05-02 04:29:55 +02:00
|
|
|
monkeypatch.setattr('thefuck.main.Popen', Popen)
|
|
|
|
return Popen
|
|
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def prepare(self, monkeypatch):
|
|
|
|
monkeypatch.setattr('thefuck.main.os.environ', {})
|
|
|
|
monkeypatch.setattr('thefuck.main.wait_output', lambda *_: True)
|
|
|
|
|
2015-05-03 12:46:01 +02:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def generic_shell(self, monkeypatch):
|
|
|
|
monkeypatch.setattr('thefuck.shells.from_shell', lambda x: x)
|
|
|
|
monkeypatch.setattr('thefuck.shells.to_shell', lambda x: x)
|
|
|
|
|
2015-05-02 04:29:55 +02:00
|
|
|
def test_get_command_calls(self, Popen):
|
2015-07-17 00:09:33 +02:00
|
|
|
assert main.get_command(Mock(env={}),
|
2015-07-28 22:04:27 +03:00
|
|
|
['thefuck', 'apt-get', 'search', 'vim']) \
|
2015-04-25 02:35:26 +02:00
|
|
|
== Command('apt-get search vim', 'stdout', 'stderr')
|
2015-04-08 18:15:49 +02:00
|
|
|
Popen.assert_called_once_with('apt-get search vim',
|
|
|
|
shell=True,
|
|
|
|
stdout=PIPE,
|
2015-04-18 21:27:43 +02:00
|
|
|
stderr=PIPE,
|
2015-07-17 00:09:33 +02:00
|
|
|
env={})
|
2015-05-06 13:57:09 +02:00
|
|
|
|
2015-05-04 04:44:16 +02:00
|
|
|
@pytest.mark.parametrize('args, result', [
|
2015-08-11 10:49:19 +02:00
|
|
|
(['thefuck', ''], None),
|
|
|
|
(['thefuck', '', ''], None),
|
2015-05-04 04:44:16 +02:00
|
|
|
(['thefuck', 'ls', '-la'], 'ls -la'),
|
|
|
|
(['thefuck', 'ls'], 'ls')])
|
|
|
|
def test_get_command_script(self, args, result):
|
2015-05-02 04:29:55 +02:00
|
|
|
if result:
|
2015-07-17 00:09:33 +02:00
|
|
|
assert main.get_command(Mock(env={}), args).script == result
|
2015-05-02 04:29:55 +02:00
|
|
|
else:
|
2015-07-17 00:09:33 +02:00
|
|
|
assert main.get_command(Mock(env={}), args) is None
|