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