当前位置: 首页>>代码示例>>Python>>正文


Python workspacebuilder.WorkspaceBuilder类代码示例

本文整理汇总了Python中tmuxp.workspacebuilder.WorkspaceBuilder的典型用法代码示例。如果您正苦于以下问题:Python WorkspaceBuilder类的具体用法?Python WorkspaceBuilder怎么用?Python WorkspaceBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WorkspaceBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_window_options

def test_window_options(session):
    yaml_config = loadfixture("workspacebuilder/window_options.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

    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'])
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:27,代码来源:test_workspacebuilder.py

示例2: test_before_load_throw_error_if_file_not_exists

def test_before_load_throw_error_if_file_not_exists(server):
    config_script_not_exists = loadfixture(
        "workspacebuilder/config_script_not_exists.yaml"
    )
    sconfig = kaptan.Kaptan(handler='yaml')
    yaml = config_script_not_exists.format(
        fixtures_dir=fixtures_dir,
        script_not_exists=os.path.join(
            fixtures_dir, 'script_not_exists.sh'
        )
    )
    sconfig = sconfig.import_config(yaml).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    with temp_session(server) as sess:
        session_name = sess.name
        temp_session_exists = server.has_session(
            sess.name
        )
        assert temp_session_exists
        with pytest.raises(
            (exc.BeforeLoadScriptNotExists, OSError),
        ) as excinfo:
            builder.build(session=sess)
            excinfo.match(r'No such file or directory')
        result = server.has_session(session_name)
        assert not result, "Kills session if before_script doesn't exist"
开发者ID:fpietka,项目名称:tmuxp,代码行数:30,代码来源:test_workspacebuilder.py

示例3: test_start_directory

def test_start_directory(session, tmpdir):
    yaml_config = loadfixture("workspacebuilder/start_directory.yaml")
    test_dir = str(tmpdir.mkdir('foo bar'))
    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
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:29,代码来源:test_workspacebuilder.py

示例4: test_before_load_throw_error_if_retcode_error

def test_before_load_throw_error_if_retcode_error(server):
    config_script_fails = loadfixture(
        "workspacebuilder/config_script_fails.yaml"
    )
    sconfig = kaptan.Kaptan(handler='yaml')
    yaml = config_script_fails.format(
        fixtures_dir=fixtures_dir,
        script_failed=os.path.join(fixtures_dir, 'script_failed.sh')
    )

    sconfig = sconfig.import_config(yaml).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    builder = WorkspaceBuilder(sconf=sconfig)

    with temp_session(server) as sess:
        session_name = sess.name

        with pytest.raises(exc.BeforeLoadScriptError):
            builder.build(session=sess)

        result = server.has_session(session_name)
        assert not result, \
            "Kills session if before_script exits with errcode"
开发者ID:fpietka,项目名称:tmuxp,代码行数:25,代码来源:test_workspacebuilder.py

示例5: test_freeze_config

def test_freeze_config(session):
    yaml_config = loadfixture("workspacefreezer/sampleconfig.yaml")
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()

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

    time.sleep(.50)

    session = session
    sconf = freeze(session)

    config.validate_schema(sconf)

    sconf = config.inline(sconf)

    kaptanconf = kaptan.Kaptan()
    kaptanconf = kaptanconf.import_config(sconf)
    kaptanconf.export(
        'json',
        indent=2
    )
    kaptanconf.export(
        'yaml',
        indent=2,
        default_flow_style=False,
        safe=True
    )
开发者ID:Brotakuu,项目名称:tmuxp,代码行数:30,代码来源:test_workspacefreezer.py

示例6: test_pane_order

def test_pane_order(session):
    """Pane ordering based on position in config and ``pane_index``.

    Regression test for https://github.com/tmux-python/tmuxp/issues/15.

    """

    yaml_config = loadfixture("workspacebuilder/pane_ordering.yaml").format(
        HOME=os.path.realpath(os.path.expanduser('~'))
    )

    # test order of `panes` (and pane_index) above aganist pane_dirs
    pane_paths = [
        '/usr/bin',
        '/usr',
        '/usr/sbin',
        os.path.realpath(os.path.expanduser('~')),
    ]

    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

    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 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
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:55,代码来源:test_workspacebuilder.py

示例7: test_environment_variables

def test_environment_variables(session):
    yaml_config = loadfixture("workspacebuilder/environment_vars.yaml")
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

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

    assert session.show_environment('FOO') == 'BAR'
    assert session.show_environment('PATH') == '/tmp'
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:11,代码来源:test_workspacebuilder.py

示例8: test_automatic_rename_option

def test_automatic_rename_option(session):
    """With option automatic-rename: on."""
    yaml_config = loadfixture("workspacebuilder/window_automatic_rename.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()

    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('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')

    w.select_pane('-D')

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

    assert w.name != text_type('sh')
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:53,代码来源:test_workspacebuilder.py

示例9: test_global_options

def test_global_options(session):
    yaml_config = loadfixture("workspacebuilder/global_options.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

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

    assert "top" in s.show_option('status-position', _global=True)
    assert 493 == s.show_option('repeat-time', _global=True)
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:12,代码来源:test_workspacebuilder.py

示例10: test_session_options

def test_session_options(session):
    yaml_config = loadfixture("workspacebuilder/session_options.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)

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

    assert "/bin/sh" in s.show_option('default-shell')
    assert "/bin/sh" in s.show_option('default-command')
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:12,代码来源:test_workspacebuilder.py

示例11: test_suppress_history

def test_suppress_history(session):
    yaml_config = loadfixture("workspacebuilder/suppress_history.yaml")
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

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

    inHistoryWindow = session.find_where({'window_name': 'inHistory'})
    isMissingWindow = session.find_where({'window_name': 'isMissing'})

    def assertHistory(cmd, hist):
        return 'inHistory' in cmd and cmd.endswith(hist)

    def assertIsMissing(cmd, hist):
        return 'isMissing' in cmd and not cmd.endswith(hist)

    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
        assert correct, "Unknown sent command: [%s] in %s" % (sent_cmd, assertCase)
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:52,代码来源:test_workspacebuilder.py

示例12: test_suppress_history

def test_suppress_history(session):
    yaml_config = loadfixture("workspacebuilder/suppress_history.yaml")
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()
    sconfig = config.expand(sconfig)
    sconfig = config.trickle(sconfig)

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

    inHistoryPane = session.find_where(
        {'window_name': 'inHistory'}).attached_pane
    isMissingPane = session.find_where(
        {'window_name': 'isMissing'}).attached_pane

    def assertHistory(cmd, hist):
        return 'inHistory' in cmd and cmd == hist

    def assertIsMissing(cmd, hist):
        return 'isMissing' in cmd and cmd != hist

    for p, assertCase in [
        (inHistoryPane, assertHistory,), (isMissingPane, assertIsMissing,)
    ]:
        correct = False
        p.window.select_window()
        p.select_pane()

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

        for _ in range(10):
            time.sleep(0.1)

            # Get the contents of the pane
            session.cmd('capture-pane')
            captured_pane = session.cmd('show-buffer')
            session.cmd('delete-buffer')

            # 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
        assert correct, "Unknown sent command: [%s]" % sent_cmd
开发者ID:fpietka,项目名称:tmuxp,代码行数:48,代码来源:test_workspacebuilder.py

示例13: test_start_directory_relative

def test_start_directory_relative(session, tmpdir):
    """Same as above test, but with relative start directory, mimicing
    loading it from a location of project file. Like::

    $ tmuxp load ~/workspace/myproject/.tmuxp.yaml

    instead of::

    $ cd ~/workspace/myproject/.tmuxp.yaml
    $ tmuxp load .

    """
    yaml_config = loadfixture("workspacebuilder/start_directory_relative.yaml")

    test_dir = str(tmpdir.mkdir('foo bar'))
    config_dir = str(tmpdir.mkdir('testRelConfigDir'))
    test_config = yaml_config.format(TEST_DIR=test_dir)

    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(test_config).get()
    # the second argument of os.getcwd() mimics the behavior
    # the CLI loader will do, but it passes in the config file's location.
    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
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:48,代码来源:test_workspacebuilder.py

示例14: test_window_index

def test_window_index(session):
    yaml_config = loadfixture("workspacebuilder/window_index.yaml")
    proc = session.cmd('show-option', '-gv', 'base-index')
    base_index = int(proc.stdout[0])
    name_index_map = {'zero': 0 + base_index, 'one': 1 + base_index, 'five': 5}

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

    builder = WorkspaceBuilder(sconf=sconfig)

    for window, _ in builder.iter_create_windows(session):
        expected_index = name_index_map[window['window_name']]
        assert int(window['window_index']) == expected_index
开发者ID:digitalsatori,项目名称:tmuxp,代码行数:16,代码来源:test_workspacebuilder.py

示例15: test_split_windows

def test_split_windows(session):
    yaml_config = loadfixture("workspacebuilder/two_pane.yaml")
    s = session
    sconfig = kaptan.Kaptan(handler='yaml')
    sconfig = sconfig.import_config(yaml_config).get()

    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):
            p = p
            assert len(s._windows) == window_count
        assert isinstance(w, Window)

        assert len(s._windows) == window_count
        window_count += 1
开发者ID:fpietka,项目名称:tmuxp,代码行数:18,代码来源:test_workspacebuilder.py


注:本文中的tmuxp.workspacebuilder.WorkspaceBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。