2015-05-03 12:46:01 +02:00
|
|
|
import pytest
|
|
|
|
from thefuck import shells
|
|
|
|
|
|
|
|
|
2015-05-04 04:44:16 +02:00
|
|
|
@pytest.fixture
|
2015-05-07 13:42:52 +02:00
|
|
|
def builtins_open(mocker):
|
|
|
|
return mocker.patch('six.moves.builtins.open')
|
2015-05-04 04:44:16 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2015-05-07 13:42:52 +02:00
|
|
|
def isfile(mocker):
|
|
|
|
return mocker.patch('os.path.isfile', return_value=True)
|
2015-05-04 04:44:16 +02:00
|
|
|
|
|
|
|
|
2015-05-03 12:46:01 +02:00
|
|
|
class TestGeneric(object):
|
|
|
|
def test_from_shell(self):
|
|
|
|
assert shells.Generic().from_shell('pwd') == 'pwd'
|
|
|
|
|
|
|
|
def test_to_shell(self):
|
2015-05-04 04:44:16 +02:00
|
|
|
assert shells.Generic().to_shell('pwd') == 'pwd'
|
|
|
|
|
|
|
|
def test_put_to_history(self, builtins_open):
|
|
|
|
assert shells.Generic().put_to_history('ls') is None
|
|
|
|
assert builtins_open.call_count == 0
|
2015-05-03 12:46:01 +02:00
|
|
|
|
|
|
|
|
2015-05-04 04:44:16 +02:00
|
|
|
@pytest.mark.usefixtures('isfile')
|
2015-05-03 12:46:01 +02:00
|
|
|
class TestBash(object):
|
|
|
|
@pytest.fixture(autouse=True)
|
2015-05-07 13:42:52 +02:00
|
|
|
def Popen(self, mocker):
|
|
|
|
mock = mocker.patch('thefuck.shells.Popen')
|
2015-05-03 12:46:01 +02:00
|
|
|
mock.return_value.stdout.read.return_value = (
|
|
|
|
b'alias l=\'ls -CF\'\n'
|
|
|
|
b'alias la=\'ls -A\'\n'
|
|
|
|
b'alias ll=\'ls -alF\'')
|
|
|
|
return mock
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('before, after', [
|
|
|
|
('pwd', 'pwd'),
|
|
|
|
('ll', 'ls -alF')])
|
|
|
|
def test_from_shell(self, before, after):
|
|
|
|
assert shells.Bash().from_shell(before) == after
|
|
|
|
|
|
|
|
def test_to_shell(self):
|
|
|
|
assert shells.Bash().to_shell('pwd') == 'pwd'
|
|
|
|
|
2015-05-04 04:44:16 +02:00
|
|
|
def test_put_to_history(self, builtins_open):
|
|
|
|
shells.Bash().put_to_history('ls')
|
2015-05-07 13:42:52 +02:00
|
|
|
builtins_open.return_value.__enter__.return_value. \
|
2015-05-04 04:44:16 +02:00
|
|
|
write.assert_called_once_with('ls\n')
|
2015-05-03 12:46:01 +02:00
|
|
|
|
2015-05-04 04:44:16 +02:00
|
|
|
|
|
|
|
@pytest.mark.usefixtures('isfile')
|
2015-05-03 12:46:01 +02:00
|
|
|
class TestZsh(object):
|
|
|
|
@pytest.fixture(autouse=True)
|
2015-05-07 13:42:52 +02:00
|
|
|
def Popen(self, mocker):
|
|
|
|
mock = mocker.patch('thefuck.shells.Popen')
|
2015-05-03 12:46:01 +02:00
|
|
|
mock.return_value.stdout.read.return_value = (
|
|
|
|
b'l=\'ls -CF\'\n'
|
|
|
|
b'la=\'ls -A\'\n'
|
|
|
|
b'll=\'ls -alF\'')
|
|
|
|
return mock
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('before, after', [
|
|
|
|
('pwd', 'pwd'),
|
|
|
|
('ll', 'ls -alF')])
|
|
|
|
def test_from_shell(self, before, after):
|
|
|
|
assert shells.Zsh().from_shell(before) == after
|
|
|
|
|
|
|
|
def test_to_shell(self):
|
2015-05-04 04:44:16 +02:00
|
|
|
assert shells.Zsh().to_shell('pwd') == 'pwd'
|
|
|
|
|
2015-05-07 13:42:52 +02:00
|
|
|
def test_put_to_history(self, builtins_open, mocker):
|
|
|
|
mocker.patch('thefuck.shells.time',
|
|
|
|
return_value=1430707243.3517463)
|
2015-05-04 04:44:16 +02:00
|
|
|
shells.Zsh().put_to_history('ls')
|
|
|
|
builtins_open.return_value.__enter__.return_value. \
|
2015-05-07 13:51:27 +02:00
|
|
|
write.assert_called_once_with(': 1430707243:0;ls\n')
|