Skip to content

Commit 212f2c7

Browse files
committed
coverage for which function, use .info log fixes #12
1 parent 1d0b634 commit 212f2c7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

libtmux/common.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,13 +328,18 @@ def get_by_id(self, id):
328328
return None
329329

330330

331-
def which(exe=None):
331+
def which(exe=None,
332+
default_paths=[
333+
'/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin']
334+
):
332335
"""Return path of bin. Python clone of /usr/bin/which.
333336
334337
from salt.util - https://www.github.com/saltstack/salt - license apache
335338
336339
:param exe: Application to search PATHs for.
337340
:type exe: string
341+
:param default_path: Application to search PATHs for.
342+
:type default_path: list
338343
:rtype: string
339344
340345
"""
@@ -352,17 +357,15 @@ def _is_executable_file_or_link(exe):
352357
# win' for cases to find optional alternatives
353358
search_path = os.environ.get('PATH') and \
354359
os.environ['PATH'].split(os.pathsep) or list()
355-
for default_path in [
356-
'/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin'
357-
]:
360+
for default_path in default_paths:
358361
if default_path not in search_path:
359362
search_path.append(default_path)
360363
os.environ['PATH'] = os.pathsep.join(search_path)
361364
for path in search_path:
362365
full_path = os.path.join(path, exe)
363366
if _is_executable_file_or_link(full_path):
364367
return full_path
365-
logger.trace(
368+
logger.info(
366369
'\'{0}\' could not be found in the following search path: '
367370
'\'{1}\''.format(exe, search_path))
368371

tests/test_common.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from libtmux.common import has_required_tmux_version
8+
from libtmux.common import has_required_tmux_version, which
99
from libtmux.exc import LibTmuxException
1010

1111
version_regex = re.compile(r'[0-9]\.[0-9]')
@@ -44,3 +44,9 @@ def test_error_version_less_1_7():
4444
excinfo.match(r'tmuxp only supports')
4545

4646
has_required_tmux_version('1.9a')
47+
48+
49+
def test_which_no_tmuxp_found(monkeypatch):
50+
monkeypatch.setenv("PATH", "/")
51+
which('tmuxp')
52+
which('tmuxp', '/')

0 commit comments

Comments
 (0)