How to use the libtmux.test.retry function in libtmux

To help you get started, we’ve selected a few libtmux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def assert_last_line(p, s):
        correct = False

        while retry():
            pane_out = p.cmd('capture-pane', '-p', '-J').stdout
            while not pane_out[-1].strip():  # delete trailing lines tmux 1.8
                pane_out.pop()
            if len(pane_out) > 1 and pane_out[-2].strip() == s:
                correct = True
                break

        # Print output for easier debugging if assertion fails
        if not correct:
            print('\n'.join(pane_out))

        return correct
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
# get the pane index for each pane
    pane_base_indexes = []
    for pane in session.attached_window.panes:
        pane_base_indexes.append(int(pane.index))

    pane_indexes_should_be = [pane_base_index + x for x in range(0, 3)]
    assert pane_indexes_should_be == pane_base_indexes

    w = session.attached_window

    assert w.name != 'man'

    pane_path = '/usr'

    while retry():
        p = w.attached_pane
        p.server._update_panes()
        if p.current_path == pane_path:
            break

    assert p.current_path == pane_path

    proc = session.cmd('show-option', '-gv', 'base-index')
    base_index = int(proc.stdout[0])
    session.server._update_windows()

    window3 = session.find_where({'window_index': str(base_index + 2)})
    assert isinstance(window3, Window)

    p = None
    pane_path = '/'
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
sconfig = config.expand(sconfig, config_dir)

    sconfig = config.trickle(sconfig)

    assert os.path.exists(config_dir)
    assert os.path.exists(test_dir)
    builder = WorkspaceBuilder(sconf=sconfig)
    builder.build(session=session)

    assert session == builder.session

    dirs = ['/usr/bin', '/dev', test_dir, config_dir, config_dir]

    for path, window in zip(dirs, session.windows):
        for p in window.panes:
            while retry():
                p.server._update_panes()
                # Handle case where directories resolve to /private/ in OSX
                pane_path = p.current_path
                if pane_path is None:
                    pass
                elif path in pane_path or pane_path == path:
                    result = path == pane_path or path in pane_path
                    break

            assert result
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
test_config = yaml_config.format(TMP_DIR=str(tmpdir), TEST_DIR=test_dir)

    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(test_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)
    builder.build(session=session)

    assert session == builder.session
    dirs = ['/usr/bin', '/dev', test_dir, '/usr', '/usr']

    for path, window in zip(dirs, session.windows):
        for p in window.panes:
            while retry():
                p.server._update_panes()
                pane_path = p.current_path
                if pane_path is None:
                    pass
                elif path in pane_path or pane_path == path:
                    result = path == pane_path or path in pane_path
                    break

            # handle case with OS X adding /private/ to /tmp/ paths
            assert result
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
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('automatic-rename') == 'on'

        assert len(s._windows) == window_count

        window_count += 1
        w.select_layout(wconf['layout'])

    assert s.name != 'tmuxp'
    w = s.windows[0]

    while retry():
        session.server._update_windows()
        if w.name != 'sh':
            break

    assert w.name != 'sh'

    pane_base_index = w.show_window_option('pane-base-index', g=True)
    w.select_pane(pane_base_index)

    while retry():
        session.server._update_windows()
        if w.name == 'sh':
            break

    assert w.name == text_type('sh')
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
for w, window_name, assertCase in [
        (inHistoryWindow, 'inHistory', assertHistory),
        (isMissingWindow, 'isMissing', assertIsMissing),
    ]:
        assert w.name == window_name
        correct = False
        w.select_window()
        p = w.attached_pane
        p.select_pane()

        # Print the last-in-history command in the pane
        p.cmd('send-keys', ' fc -ln -1')
        p.cmd('send-keys', 'Enter')

        buffer_name = 'test'
        while retry():
            # from v0.7.4 libtmux session.cmd adds target -t self.id by default
            # show-buffer doesn't accept -t, use global cmd.

            # Get the contents of the pane
            p.cmd('capture-pane', '-b', buffer_name)

            captured_pane = session.server.cmd('show-buffer', '-b', buffer_name)
            session.server.cmd('delete-buffer', '-b', buffer_name)

            # Parse the sent and last-in-history commands
            sent_cmd = captured_pane.stdout[0].strip()
            history_cmd = captured_pane.stdout[-2].strip()

            if assertCase(sent_cmd, history_cmd):
                correct = True
                break
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
def test_window_shell(session):
    yaml_config = loadfixture("workspacebuilder/window_shell.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    for w, wconf in builder.iter_create_windows(s):
        if 'window_shell' in wconf:
            assert wconf['window_shell'] == text_type('top')

        while retry():
            session.server._update_windows()
            if w['window_name'] != 'top':
                break

        assert w.name != text_type('top')
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
assert isinstance(w, Window)

        assert len(s._windows) == window_count
        window_count += 1

    for w in session.windows:
        pane_base_index = w.show_window_option('pane-base-index', g=True)
        for p_index, p in enumerate(w.list_panes(), start=pane_base_index):
            assert int(p_index) == int(p.index)

            # pane-base-index start at base-index, pane_paths always start
            # at 0 since python list.
            pane_path = pane_paths[p_index - pane_base_index]

            while retry():
                p.server._update_panes()
                if p.current_path == pane_path:
                    break

            assert p.current_path, pane_path