mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
Merge pull request #505 from scorphus/decode-bin
#504: Decode binary name if on Python 2
This commit is contained in:
commit
d2b0b6e8ec
@ -1,4 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import pytest
|
||||
import warnings
|
||||
from mock import Mock
|
||||
import six
|
||||
from thefuck.utils import default_settings, \
|
||||
@ -233,11 +236,17 @@ class TestCompatibilityCall(object):
|
||||
|
||||
|
||||
class TestGetValidHistoryWithoutCurrent(object):
|
||||
@pytest.yield_fixture(autouse=True)
|
||||
def fail_on_warning(self):
|
||||
warnings.simplefilter('error')
|
||||
yield
|
||||
warnings.resetwarnings()
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def history(self, mocker):
|
||||
return mocker.patch('thefuck.shells.shell.get_history',
|
||||
return_value=['le cat', 'fuck', 'ls cat',
|
||||
'diff x', 'nocommand x'])
|
||||
'diff x', 'nocommand x', u'café ô'])
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def alias(self, mocker):
|
||||
@ -245,14 +254,22 @@ class TestGetValidHistoryWithoutCurrent(object):
|
||||
return_value='fuck')
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def callables(self, mocker):
|
||||
return mocker.patch('thefuck.utils.get_all_executables',
|
||||
return_value=['diff', 'ls'])
|
||||
def bins(self, mocker, monkeypatch):
|
||||
monkeypatch.setattr('thefuck.conf.os.environ', {'PATH': 'path'})
|
||||
callables = list()
|
||||
for name in ['diff', 'ls', 'café']:
|
||||
bin_mock = mocker.Mock(name=name)
|
||||
bin_mock.configure_mock(name=name, is_dir=lambda: False)
|
||||
callables.append(bin_mock)
|
||||
path_mock = mocker.Mock(iterdir=mocker.Mock(return_value=callables))
|
||||
return mocker.patch('thefuck.utils.Path', return_value=path_mock)
|
||||
|
||||
@pytest.mark.parametrize('script, result', [
|
||||
('le cat', ['ls cat', 'diff x']),
|
||||
('diff x', ['ls cat']),
|
||||
('fuck', ['ls cat', 'diff x'])])
|
||||
('le cat', ['ls cat', 'diff x', u'café ô']),
|
||||
('diff x', ['ls cat', u'café ô']),
|
||||
('fuck', ['ls cat', 'diff x', u'café ô']),
|
||||
(u'cafe ô', ['ls cat', 'diff x', u'café ô']),
|
||||
])
|
||||
def test_get_valid_history_without_current(self, script, result):
|
||||
command = Command(script=script)
|
||||
assert get_valid_history_without_current(command) == result
|
||||
|
@ -110,7 +110,7 @@ def get_all_executables():
|
||||
tf_entry_points = get_installation_info().get_entry_map()\
|
||||
.get('console_scripts', {})\
|
||||
.keys()
|
||||
bins = [exe.name
|
||||
bins = [exe.name.decode('utf8') if six.PY2 else exe.name
|
||||
for path in os.environ.get('PATH', '').split(':')
|
||||
for exe in _safe(lambda: list(Path(path).iterdir()), [])
|
||||
if not _safe(exe.is_dir, True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user