From ed38fedf2684ff00f1f4a12f6b5c45ce84c64765 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Sun, 8 May 2016 13:20:37 -0300 Subject: [PATCH] #504: Mock `get_all_executables` internals instead --- tests/test_utils.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/test_utils.py b/tests/test_utils.py index 4441a8e..6c288c2 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -245,9 +245,16 @@ 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']),