1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-19 04:21:14 +00:00
thefuck/tests/test_main.py

47 lines
1.7 KiB
Python
Raw Normal View History

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)
@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):
assert main.get_command(Mock(env={}),
2015-07-28 22:04:27 +03:00
['thefuck', 'apt-get', 'search', 'vim']) \
== 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,
stderr=PIPE,
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:
assert main.get_command(Mock(env={}), args).script == result
2015-05-02 04:29:55 +02:00
else:
assert main.get_command(Mock(env={}), args) is None