예제 #1
0
def test_env_change_set(monkeypatch, caplog):
    env = EnvChangeSet("bach", 1685)
    assert env.var == "bach"
    assert env.val == 1685
    with pytest.raises(FatalKrunError):
        env.apply({"bach": 1695})
    assert "Environment bach is already defined" in caplog.text
예제 #2
0
파일: test_env.py 프로젝트: bennn/krun
def test_env_change_set(monkeypatch, caplog):
    env = EnvChangeSet("bach", 1685)
    assert env.var == "bach"
    assert env.val == 1685
    with pytest.raises(FatalKrunError):
        env.apply({"bach": 1695})
    assert "Environment bach is already defined" in caplog.text()
예제 #3
0
def _run_shell_cmd_start_process(cmd, extra_env):
    debug("execute shell cmd: %s" % cmd)

    env = os.environ.copy()
    if extra_env:
        # Use EnvChangeSet so that we crash out if extra_env conflicts
        # with the current environment.
        from krun.env import EnvChangeSet
        for var, val in extra_env.iteritems():
            ec = EnvChangeSet(var, val)
            ec.apply(env)

    return Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env)
예제 #4
0
파일: util.py 프로젝트: bennn/krun
def run_shell_cmd(cmd, failure_fatal=True, extra_env=None):
    debug("execute shell cmd: %s" % cmd)

    env = os.environ.copy()
    if extra_env:
        # Use EnvChangeSet so that we crash out if extra_env conflicts
        # with the current environment.
        from krun.env import EnvChangeSet
        for var, val in extra_env.iteritems():
            ec = EnvChangeSet(var, val)
            ec.apply(env)

    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env)
    stdout, stderr = p.communicate()
    rc = p.wait()
    if failure_fatal and rc != 0:
        msg = "Command failed: '%s'\n" % cmd
        msg += "stdout:\n%s\n" % stdout
        msg += "stderr:\n%s\n" % stderr
        fatal(msg)
    return stdout.strip(), stderr.strip(), rc
예제 #5
0
def run_shell_cmd(cmd, failure_fatal=True, extra_env=None):
    debug("execute shell cmd: %s" % cmd)

    env = os.environ.copy()
    if extra_env:
        # Use EnvChangeSet so that we crash out if extra_env conflicts
        # with the current environment.
        from krun.env import EnvChangeSet
        for var, val in extra_env.iteritems():
            ec = EnvChangeSet(var, val)
            ec.apply(env)

    p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, env=env)
    stdout, stderr = p.communicate()
    rc = p.wait()
    if failure_fatal and rc != 0:
        msg = "Command failed: '%s'\n" % cmd
        msg += "stdout:\n%s\n" % stdout
        msg += "stderr:\n%s\n" % stderr
        fatal(msg)
    return stdout.strip(), stderr.strip(), rc
예제 #6
0
def test_env_change_set_apply():
    env = EnvChangeSet("bach", 1685)
    my_dict = {"handel": 1685}
    env.apply(my_dict)
    assert my_dict["bach"] == 1685
    assert my_dict["handel"] == 1685
예제 #7
0
파일: test_env.py 프로젝트: bennn/krun
def test_env_change_set_apply():
    env = EnvChangeSet("bach", 1685)
    my_dict = {"handel": 1685}
    env.apply(my_dict)
    assert my_dict["bach"] == 1685
    assert my_dict["handel"] == 1685