Skip to content

Commit 6f92f6b

Browse files
committed
add tests and support for TmuxCommandNotFound
1 parent 4c4aea2 commit 6f92f6b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

libtmux/common.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ class tmux_cmd(object):
127127

128128
""":term:`tmux(1)` command via :py:mod:`subprocess`.
129129
130+
:param tmux_search_paths: Default PATHs to search tmux for, defaults to
131+
``default_paths`` used in :func:`which`.
132+
:type tmux_search_path: list
133+
:param append_env_path: Append environment PATHs to tmux search paths.
134+
:type append_env_path: bool
135+
130136
Usage::
131137
132138
proc = tmux_cmd('new-session', '-s%' % 'my session')
@@ -150,8 +156,13 @@ class tmux_cmd(object):
150156
"""
151157

152158
def __init__(self, *args, **kwargs):
153-
154-
tmux_bin = which('tmux')
159+
tmux_bin = which(
160+
'tmux',
161+
default_paths=kwargs.get('tmux_search_paths', [
162+
'/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin'
163+
]),
164+
append_env_path=kwargs.get('append_env_path', True)
165+
)
155166
if not tmux_bin:
156167
raise(exc.TmuxCommandNotFound)
157168

tests/test_common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import pytest
77

88
from libtmux.common import (
9-
has_required_tmux_version, which, session_check_name, is_version
9+
has_required_tmux_version, which, session_check_name, is_version, tmux_cmd
1010
)
11-
from libtmux.exc import LibTmuxException, BadSessionName
11+
from libtmux.exc import LibTmuxException, BadSessionName, TmuxCommandNotFound
1212

1313
version_regex = re.compile(r'([0-9]\.[0-9])|(master)')
1414

@@ -61,10 +61,18 @@ def test_error_version_less_1_7():
6161
def test_which_no_bin_found(monkeypatch):
6262
monkeypatch.setenv("PATH", "/")
6363
assert which('top')
64-
assert which('top', default_paths=['/'])
64+
assert which('top', default_paths=[])
65+
assert not which('top', default_paths=[], append_env_path=False)
6566
assert not which('top', default_paths=['/'], append_env_path=False)
6667

6768

69+
def test_tmux_cmd_raises_on_not_found(monkeypatch):
70+
with pytest.raises(TmuxCommandNotFound):
71+
tmux_cmd('-V', tmux_search_paths=[], append_env_path=False)
72+
73+
tmux_cmd('-V')
74+
75+
6876
@pytest.mark.parametrize("session_name,raises,exc_msg_regex", [
6977
('', True, 'may not be empty'),
7078
(None, True, 'may not be empty'),

0 commit comments

Comments
 (0)