diff --git a/tests/test_utils.py b/tests/test_utils.py index cf9208b8..3e73c3d7 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -2,7 +2,7 @@ import pytest import warnings -from mock import Mock, patch +from mock import Mock, call, patch from thefuck.utils import default_settings, \ memoize, get_closest, get_all_executables, replace_argument, \ get_all_matched_commands, is_app, for_app, cache, \ @@ -76,6 +76,24 @@ def test_get_all_executables(): assert 'fuck' not in all_callables +@pytest.fixture +def os_environ_pathsep(monkeypatch, path, pathsep): + env = {'PATH': path} + monkeypatch.setattr('os.environ', env) + monkeypatch.setattr('os.pathsep', pathsep) + return env + + +@pytest.mark.usefixtures('no_memoize', 'os_environ_pathsep') +@pytest.mark.parametrize('path, pathsep', [ + ('/foo:/bar:/baz:/foo/bar', ':'), + (r'C:\\foo;C:\\bar;C:\\baz;C:\\foo\\bar', ';')]) +def test_get_all_executables_pathsep(path, pathsep): + with patch('thefuck.utils.Path') as Path_mock: + get_all_executables() + Path_mock.assert_has_calls([call(p) for p in path.split(pathsep)], True) + + @pytest.mark.parametrize('args, result', [ (('apt-get instol vim', 'instol', 'install'), 'apt-get install vim'), (('git brnch', 'brnch', 'branch'), 'git branch')]) diff --git a/thefuck/utils.py b/thefuck/utils.py index bd8028ec..6112c019 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -118,7 +118,7 @@ def get_all_executables(): tf_entry_points = ['thefuck', 'fuck'] bins = [exe.name.decode('utf8') if six.PY2 else exe.name - for path in os.environ.get('PATH', '').split(':') + for path in os.environ.get('PATH', '').split(os.pathsep) for exe in _safe(lambda: list(Path(path).iterdir()), []) if not _safe(exe.is_dir, True) and exe.name not in tf_entry_points]