1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-20 20:09:07 +00:00

#504: UTF8-decode bin names if on Python 2

Fix #504
This commit is contained in:
Pablo Santiago Blum de Aguiar 2016-05-08 13:20:37 -03:00
parent ed38fedf26
commit 561eb12c08
2 changed files with 16 additions and 6 deletions

View File

@ -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):
@ -255,11 +264,12 @@ class TestGetValidHistoryWithoutCurrent(object):
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

View File

@ -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)