How to use the tmuxp.exc.BeforeLoadScriptError function in tmuxp

To help you get started, we’ve selected a few tmuxp 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_util.py View on Github external
def test_beforeload_returncode():
    script_file = os.path.join(fixtures_dir, 'script_failed.sh')

    with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
        run_before_script(script_file)
        assert excinfo.match(r'113')
github tmux-python / tmuxp / tests / test_workspacebuilder.py View on Github external
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"
github tmux-python / tmuxp / tests / test_util.py View on Github external
def test_raise_BeforeLoadScriptError_if_retcode():
    script_file = os.path.join(fixtures_dir, 'script_failed.sh')

    with pytest.raises(BeforeLoadScriptError):
        run_before_script(script_file)
github tmux-python / tmuxp / tests / test_util.py View on Github external
def test_beforeload_returns_stderr_messages():
    script_file = os.path.join(fixtures_dir, 'script_failed.sh')

    with pytest.raises(exc.BeforeLoadScriptError) as excinfo:
        run_before_script(script_file)
        assert excinfo.match(r'failed with returncode')
github tmux-python / tmuxp / tmuxp / util.py View on Github external
shlex.split(str(script_file)),
            stderr=subprocess.PIPE,
            stdout=subprocess.PIPE,
            cwd=cwd,
        )
        for line in iter(proc.stdout.readline, b''):
            sys.stdout.write(console_to_str(line))
        proc.wait()

        if proc.returncode:
            stderr = proc.stderr.read()
            proc.stderr.close()
            stderr = console_to_str(stderr).split('\n')
            stderr = '\n'.join(list(filter(None, stderr)))  # filter empty

            raise exc.BeforeLoadScriptError(
                proc.returncode, os.path.abspath(script_file), stderr
            )

        return proc.returncode
    except OSError as e:
        if e.errno == 2:
            raise exc.BeforeLoadScriptNotExists(e, os.path.abspath(script_file))
        else:
            raise e