Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_has_gte_version():
assert has_gte_version('1.6')
assert has_gte_version('1.6b')
assert has_gte_version(str(get_version()))
assert not has_gte_version('4.0')
assert not has_gte_version('4.0b')
if has_gte_version('2.3'):
sconfig['windows'][0]['options']['pane-border-format'] = ' #P '
builder = WorkspaceBuilder(sconf=sconfig)
window_count = len(session._windows) # current window count
assert len(s._windows) == window_count
for w, wconf in builder.iter_create_windows(s):
for p in builder.iter_create_panes(w, wconf):
w.select_layout('tiled') # fix glitch with pane size
p = p
assert len(s._windows) == window_count
assert isinstance(w, Window)
assert w.show_window_option('main-pane-height') == 5
if has_gte_version('2.3'):
assert w.show_window_option('pane-border-format') == ' #P '
assert len(s._windows) == window_count
window_count += 1
w.select_layout(wconf['layout'])
def test_allows_master_version(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
stdout = ['tmux master']
stderr = None
return Hi()
monkeypatch.setattr(libtmux.common, 'tmux_cmd', mock_tmux_cmd)
assert has_minimum_version()
assert has_gte_version(TMUX_MIN_VERSION)
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
assert (
'%s-master' % TMUX_MAX_VERSION == get_version()
), "Is the latest supported version with -master appended"
def test_get_version_openbsd(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
stderr = ['tmux: unknown option -- V']
return Hi()
monkeypatch.setattr(libtmux.common, 'tmux_cmd', mock_tmux_cmd)
monkeypatch.setattr(sys, 'platform', 'openbsd 5.2')
assert has_minimum_version()
assert has_gte_version(TMUX_MIN_VERSION)
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
assert (
'%s-openbsd' % TMUX_MAX_VERSION == get_version()
), "Is the latest supported version with -openbsd appended"
def test_has_session(server, session):
"""Server.has_session returns True if has session_name exists."""
TEST_SESSION_NAME = session.get('session_name')
assert server.has_session(TEST_SESSION_NAME)
if has_gte_version('2.1'):
assert not server.has_session(TEST_SESSION_NAME[:-2])
assert server.has_session(TEST_SESSION_NAME[:-2], exact=False)
assert not server.has_session('asdf2314324321')
def test_allows_next_version(monkeypatch):
def mock_tmux_cmd(param):
class Hi(object):
stdout = ['tmux next-2.9']
stderr = None
return Hi()
monkeypatch.setattr(libtmux.common, 'tmux_cmd', mock_tmux_cmd)
assert has_minimum_version()
assert has_gte_version(TMUX_MIN_VERSION)
assert has_gt_version(TMUX_MAX_VERSION), "Greater than the max-supported version"
assert '2.9' == get_version()
def test_set_option_invalid(session):
"""Session.set_option raises UnknownOption for invalid option."""
if has_gte_version('2.4'):
with pytest.raises(exc.InvalidOption):
session.set_option('afewewfew', 43)
else:
with pytest.raises(exc.UnknownOption):
session.set_option('afewewfew', 43)
def test_has_gte_version():
assert has_gte_version('1.6')
assert has_gte_version('1.6b')
assert has_gte_version(str(get_version()))
assert not has_gte_version('4.0')
assert not has_gte_version('4.0b')
if has_gte_version('2.6'):
set_layout_hook(builder.session, 'client-session-changed')
builder.session.switch_client() # switch client to new session
os.environ['TMUX'] = tmux_env # set TMUX back again
return builder.session
else: # session created in the background, from within tmux
if has_gte_version('2.6'): # prepare for both cases
set_layout_hook(builder.session, 'client-attached')
set_layout_hook(builder.session, 'client-session-changed')
sys.exit('Session created in detached state.')
else: # tmuxp ran from inside tmux
if has_gte_version('2.6'):
# if attaching for first time
set_layout_hook(builder.session, 'client-attached')
# for cases where user switches client for first time
set_layout_hook(builder.session, 'client-session-changed')
if not detached:
builder.session.attach_session()
except exc.TmuxpException as e:
import traceback
click.echo(traceback.format_exc(), err=True)
click.echo(e, err=True)
choice = click.prompt(
exact : bool
match the session name exactly. tmux uses fnmatch by default.
Internally prepends ``=`` to the session in ``$ tmux has-session``.
tmux 2.1 and up only.
Raises
------
:exc:`exc.BadSessionName`
Returns
-------
bool
"""
session_check_name(target_session)
if exact and has_gte_version('2.1'):
target_session = '={}'.format(target_session)
proc = self.cmd('has-session', '-t%s' % target_session)
if not proc.returncode:
return True
return False