Exemple #1
0
def workspace(tmpdir, ert_storage):
    workspace_dir = pathlib.Path(tmpdir / "polynomial")
    workspace_dir.mkdir()
    with chdir(workspace_dir):
        workspace_obj = ert3.workspace.initialize(workspace_dir)
        ert.storage.init(workspace_name=workspace_obj.name)
        yield workspace_obj
Exemple #2
0
def test_cli_local_test_run(tmpdir):
    with chdir(tmpdir):
        with Storage.start_server():
            args = ["ert3", "init", "--example", "polynomial"]
            with patch.object(sys, "argv", args):
                ert3.console._console._main()

            os.chdir("polynomial")

            # Error testing is performed in this context to reduce
            # test time as a full storage server is involved.
            with pytest.raises(ert.exceptions.ExperimentError):
                with patch.object(
                    sys, "argv", ["ert3", "run", "sensitivity", "--local-test-run"]
                ):
                    ert3.console._console._main()

            with patch.object(
                sys, "argv", ["ert3", "run", "evaluation", "--local-test-run"]
            ):
                ert3.console._console._main()

            experiments = [
                experiment
                for experiment in ert.storage.get_experiment_names(
                    workspace_name="polynomial"
                )
                if experiment.startswith("evaluation-")
            ]
            assert len(experiments) == 1
            run_id = experiments[0].split("-")[1]
            assert pathlib.Path(f"local-test-run-{run_id}/output.json").exists()
Exemple #3
0
def test_cli_local_test_run_specific_realization(tmpdir):
    with chdir(tmpdir):
        with Storage.start_server():
            args = ["ert3", "init", "--example", "polynomial"]
            with patch.object(sys, "argv", args):
                ert3.console._console._main()

            os.chdir("polynomial")

            with pytest.raises(ert.exceptions.ExperimentError):
                with patch.object(
                    sys, "argv", ["ert3", "run", "evaluation", "--realization", "2"]
                ):
                    ert3.console._console._main()

            poly_size = yaml.safe_load(
                pathlib.Path("experiments/evaluation/ensemble.yml").read_text(
                    encoding="utf-8"
                )
            )["size"]
            not_existing_realization = poly_size  # zero-indexed realizations

            with pytest.raises(
                ert.exceptions.ConfigValidationError,
                match="Realization out of ensemble bounds",
            ):
                assert not_existing_realization > poly_size - 1
                with patch.object(
                    sys,
                    "argv",
                    [
                        "ert3",
                        "run",
                        "evaluation",
                        "--local-test-run",
                        "--realization",
                        str(not_existing_realization),
                    ],
                ):
                    ert3.console._console._main()

            with patch.object(
                sys,
                "argv",
                ["ert3", "run", "evaluation", "--local-test-run", "--realization", "2"],
            ):
                ert3.console._console._main()

            experiments = [
                experiment
                for experiment in ert.storage.get_experiment_names(
                    workspace_name="polynomial"
                )
                if experiment.startswith("evaluation-")
            ]
            assert len(experiments) == 1
            run_id = experiments[0].split("-")[1]
            assert pathlib.Path(f"local-test-run-{run_id}/output.json").exists()
Exemple #4
0
def test_cli_init_subfolder(workspace):
    (workspace._path / "sub_folder").mkdir()
    with chdir(workspace._path / "sub_folder"):
        args = ["ert3", "init"]
        with patch.object(sys, "argv", args):
            with pytest.raises(
                    ert.exceptions.IllegalWorkspaceOperation,
                    match="Already inside an ERT workspace",
            ):
                ert3.console._console._main()
Exemple #5
0
def workspace_integration(tmpdir):
    from ert_shared.services import Storage

    workspace_dir = pathlib.Path(tmpdir / "polynomial")
    workspace_dir.mkdir()
    with chdir(workspace_dir):

        with Storage.start_server():
            workspace_obj = ert3.workspace.initialize(workspace_dir)
            ert.storage.init(workspace_name=workspace_obj.name)
            yield workspace_obj