Exemple #1
0
    def test_create(self):
        with self.assertRaises(OSError):
            r = RMSRun(0, "/project/does/not/exist", "workflow")

        with TestAreaContext("test_create"):
            os.mkdir("rms")
            r = RMSRun(0, "rms", "workflow")
Exemple #2
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()
Exemple #3
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
Exemple #4
0
    def test_create(self):
        os.environ["RMS_SITE_CONFIG"] =os.path.join(self.SOURCE_ROOT, "python/res/fm/rms/rms_config.yml")
        with self.assertRaises(OSError):
            r = RMSRun(0, "/project/does/not/exist", "workflow")

        with TestAreaContext("test_create"):
            os.mkdir("rms")
            r = RMSRun(0, "rms", "workflow")
Exemple #5
0
def test_run_class_multi_seed(tmpdir, monkeypatch, test_input, expected_result):
    with open("rms_config.yml", "w") as f:
        f.write("executable:  {}/bin/rms".format(os.getcwd()))

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

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

    seed_file = ["3", "422851785", "723121249", "132312123"]
    with open("run_path/random.seeds", "w") as f:
        f.write("\n".join(seed_file))

    r = RMSRun(test_input, "project", "workflow", run_path="run_path")
    assert r.seed == expected_result
Exemple #6
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": "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()
Exemple #7
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,
                             "tests/libres_tests/res/fm/rms"), "bin")
            self.monkeypatch.setenv("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",
                       allow_no_env=True)
            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",
                       allow_no_env=True)
            with self.assertRaises(RMSRunException):
                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",
                allow_no_env=True,
            )
            with self.assertRaises(RMSRunException):
                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",
                allow_no_env=True,
            )
            r.run()