From: Alfredo Deza Date: Mon, 26 Feb 2018 21:27:38 +0000 (-0500) Subject: ceph-volume tests.util ensure behavior of new which utility X-Git-Tag: v13.0.2~125^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=d26215a49b5d850a2bff6e75cfef7a036f1da60d;p=ceph.git ceph-volume tests.util ensure behavior of new which utility Signed-off-by: Alfredo Deza --- diff --git a/src/ceph-volume/ceph_volume/tests/util/test_system.py b/src/ceph-volume/ceph_volume/tests/util/test_system.py index a742de4804ce..690147cb29b3 100644 --- a/src/ceph-volume/ceph_volume/tests/util/test_system.py +++ b/src/ceph-volume/ceph_volume/tests/util/test_system.py @@ -166,3 +166,29 @@ class TestIsBinary(object): def test_is_not_binary(self, tmpfile): binary_path = tmpfile(contents='asd\n\nlkjh0') assert system.is_binary(binary_path) is False + + +class TestWhich(object): + + def test_executable_exists_but_is_not_file(self, monkeypatch): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: False) + monkeypatch.setattr(system.os.path, 'exists', lambda x: True) + assert system.which('exedir') == 'exedir' + + def test_executable_does_not_exist(self, monkeypatch): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: False) + monkeypatch.setattr(system.os.path, 'exists', lambda x: False) + assert system.which('exedir') == 'exedir' + + def test_executable_exists_as_file(self, monkeypatch): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: True) + monkeypatch.setattr(system.os.path, 'exists', lambda x: True) + assert system.which('ceph') == '/usr/local/bin/ceph' + + def test_warnings_when_executable_isnt_matched(self, monkeypatch, capsys): + monkeypatch.setattr(system.os.path, 'isfile', lambda x: True) + monkeypatch.setattr(system.os.path, 'exists', lambda x: False) + system.which('exedir') + stdout, stderr = capsys.readouterr() + assert 'Absolute path not found for executable: exedir' in stdout + assert 'Ensure $PATH environment variable contains common executable locations' in stdout