1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-10-30 06:34:09 +00:00

#N/A Add ability to get shell history

This commit is contained in:
nvbn
2015-07-10 16:42:21 +03:00
parent c7071763a3
commit 4b4e7acc0f
2 changed files with 62 additions and 4 deletions

View File

@@ -12,6 +12,16 @@ def isfile(mocker):
return mocker.patch('os.path.isfile', return_value=True)
@pytest.fixture
@pytest.mark.usefixtures('isfile')
def history_lines(mocker):
def aux(lines):
mock = mocker.patch('io.open')
mock.return_value.__enter__\
.return_value.__iter__.return_value = lines
return aux
class TestGeneric(object):
@pytest.fixture
def shell(self):
@@ -38,6 +48,12 @@ class TestGeneric(object):
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()
def test_get_history(self, history_lines, shell):
history_lines(['ls', 'rm'])
# We don't know what to do in generic shell with history lines,
# so just ignore them:
assert list(shell.get_history()) == []
@pytest.mark.usefixtures('isfile')
class TestBash(object):
@@ -85,6 +101,10 @@ class TestBash(object):
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()
def test_get_history(self, history_lines, shell):
history_lines(['ls', 'rm'])
assert list(shell.get_history()) == ['ls', 'rm']
@pytest.mark.usefixtures('isfile')
class TestFish(object):
@@ -187,3 +207,7 @@ class TestZsh(object):
assert 'alias fuck' in shell.app_alias()
assert 'thefuck' in shell.app_alias()
assert 'TF_ALIAS' in shell.app_alias()
def test_get_history(self, history_lines, shell):
history_lines([': 1432613911:0;ls', ': 1432613916:0;rm'])
assert list(shell.get_history()) == ['ls', 'rm']