Пример #1
0
    def test_run_class_with_existing_target_file(self):
        with TestAreaContext("test_run_existing_target"):
            with open("rms_config.yml", "w") as f:
                f.write("executable:  {}/bin/rms".format(os.getcwd()))

            os.mkdir("run_path")
            os.mkdir("bin")
            os.mkdir("project")
            shutil.copy(
                os.path.join(self.SOURCE_ROOT,
                             "tests/libres_tests/res/fm/rms"), "bin")
            self.monkeypatch.setenv("RMS_SITE_CONFIG", "rms_config.yml")

            target_file = os.path.join(os.getcwd(), "rms_target_file")
            action = {
                "exit_status": 0,
                "target_file": target_file,
            }
            with open("run_path/action.json", "w") as f:
                f.write(json.dumps(action))

            with open(target_file, "w") as f:
                f.write("This is a dummy target file")

            r = RMSRun(
                0,
                "project",
                "workflow",
                run_path="run_path",
                target_file=target_file,
                allow_no_env=True,
            )
            r.run()
Пример #2
0
def test_run_backup_python_path(tmpdir, monkeypatch, python_path):
    with open("rms_config.yml", "w") as f:
        f.write("executable:  {}/bin/rms".format(os.getcwd()))

    os.mkdir("run_path")
    os.mkdir("bin")
    os.mkdir("project")
    shutil.copy(os.path.join(source_root(), "python/tests/res/fm/rms"), "bin")
    monkeypatch.setenv("RMS_SITE_CONFIG", "rms_config.yml")
    if python_path is None:
        monkeypatch.delenv("PYTHONPATH")
    else:
        monkeypatch.setenv("PYTHONPATH", python_path)

    action = {"exit_status": 0}
    with open("run_path/action.json", "w") as f:
        f.write(json.dumps(action))

    r = RMSRun(0, "project", "workflow", run_path="run_path")
    r.run()

    with open('run_path/env.json') as f:
        env = json.load(f)

    assert env['_PRE_RMS_BACKUP'] == "1"
    if python_path is None:
        assert '_PRE_RMS_PYTHONPATH' not in env
    else:
        assert env['_PRE_RMS_PYTHONPATH'] == python_path
Пример #3
0
    def test_run_class(self):
        with TestAreaContext("test_run"):
            with open("rms_config.yml", "w") as f:
                f.write("executable:  {}/bin/rms".format(os.getcwd()))

            os.mkdir("run_path")
            os.mkdir("bin")
            os.mkdir("project")
            shutil.copy(
                os.path.join(self.SOURCE_ROOT, "python/tests/res/fm/rms"),
                "bin")
            os.environ["RMS_SITE_CONFIG"] = "rms_config.yml"

            action = {"exit_status": 0}
            with open("run_path/action.json", "w") as f:
                f.write(json.dumps(action))

            r = RMSRun(0, "project", "workflow", run_path="run_path")
            r.run()

            # -----------------------------------------------------------------

            action = {"exit_status": 1}
            with open("run_path/action.json", "w") as f:
                f.write(json.dumps(action))

            r = RMSRun(0, "project", "workflow", run_path="run_path")
            with self.assertRaises(Exception):
                r.run()

            # -----------------------------------------------------------------

            action = {"exit_status": 0}
            with open("run_path/action.json", "w") as f:
                f.write(json.dumps(action))

            r = RMSRun(0,
                       "project",
                       "workflow",
                       run_path="run_path",
                       target_file="some_file")
            with self.assertRaises(Exception):
                r.run()

            # -----------------------------------------------------------------

            action = {
                "exit_status": 0,
                "target_file": os.path.join(os.getcwd(), "some_file")
            }
            with open("run_path/action.json", "w") as f:
                f.write(json.dumps(action))

            r = RMSRun(0,
                       "project",
                       "workflow",
                       run_path="run_path",
                       target_file="some_file")
            r.run()