Ejemplo n.º 1
0
def test_runpath_file(tmpdir, source_root):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )

    config_lines = [
        "LOAD_WORKFLOW_JOB ASSERT_RUNPATH_FILE\n"
        "LOAD_WORKFLOW TEST_RUNPATH_FILE\n",
        "HOOK_WORKFLOW TEST_RUNPATH_FILE PRE_SIMULATION\n",
    ]

    with tmpdir.as_cwd():
        with open("poly_example/poly.ert", "a") as fh:
            fh.writelines(config_lines)

        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_SMOOTHER_MODE,
                "--target-case",
                "poly_runpath_file",
                "--realizations",
                "1,2,4,8,16,32,64",
                "poly_example/poly.ert",
            ],
        )

        run_cli(parsed)

        assert os.path.isfile("RUNPATH_WORKFLOW_0.OK")
        assert os.path.isfile("RUNPATH_WORKFLOW_1.OK")
Ejemplo n.º 2
0
def test_ensemble_evaluator(tmpdir, source_root):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )

    with tmpdir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_SMOOTHER_MODE,
                "--target-case",
                "poly_runpath_file",
                "--realizations",
                "1,2,4,8,16,32,64",
                "--enable-ensemble-evaluator",
                "poly_example/poly.ert",
            ],
        )
        FeatureToggling.update_from_args(parsed)

        assert FeatureToggling.is_enabled("ensemble-evaluator") is True

        run_cli(parsed)
        FeatureToggling.reset()
Ejemplo n.º 3
0
def poly_example_tmp_dir_shared(
    tmp_path_factory,
    source_root,
):
    tmpdir = tmp_path_factory.mktemp("my_poly_tmp")
    poly_dir = py.path.local(os.path.join(str(tmpdir), "poly_example"))
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        poly_dir,
    )

    with poly_dir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_SMOOTHER_MODE,
                "--target-case",
                "poly_runpath_file",
                "--realizations",
                "1,2,4",
                "poly.ert",
                "--port-range",
                "1024-65535",
            ],
        )
        run_cli(parsed)
    return poly_dir
Ejemplo n.º 4
0
def test_es_mda(tmpdir, source_root):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )

    with tmpdir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ES_MDA_MODE,
                "--target-case",
                "iter-%d",
                "--realizations",
                "1,2,4,8,16",
                "poly_example/poly.ert",
                "--port-range",
                "1024-65535",
                "--weights",
                "1",
            ],
        )
        FeatureToggling.update_from_args(parsed)

        run_cli(parsed)
        FeatureToggling.reset()
Ejemplo n.º 5
0
def test_mock_bsub_fail_random(poly_case_context):
    """
    Approx 7/10 of the submits will fail due to the random generator in the
    created mocked bsub script. By using the retry functionality towards
    queue-errors in job_queue.cpp we should still manage to finalize all our runs
    before exhausting the limits
    """
    bsub_random_fail_name = "bsub_random_fail"
    introduce_bsub_failures(
        script_name=bsub_random_fail_name, fraction_successful_submits=0.3
    )

    apply_customized_config(mocked_bsub=bsub_random_fail_name)

    parser = ArgumentParser(prog="test_main")
    parsed = ert_parser(
        parser,
        [
            ENSEMBLE_EXPERIMENT_MODE,
            "poly_example/poly.ert",
            "--port-range",
            "1024-65535",
        ],
    )

    run_cli(parsed)
Ejemplo n.º 6
0
def test_cli_test_connection_error(tmpdir, source_root, capsys):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )

    mock_monitor = MagicMock()
    mock_monitor.__enter__.side_effect = ConnectionRefusedError

    with patch(
            "ert_shared.status.tracker.evaluator.create_ee_monitor",
            return_value=mock_monitor,
    ), patch(
            "ert_shared.ensemble_evaluator.evaluator.ee_monitor.create",
            return_value=mock_monitor,
    ):
        with tmpdir.as_cwd():
            parser = ArgumentParser(prog="test_main")
            parsed = ert_parser(parser,
                                [TEST_RUN_MODE, "poly_example/poly.ert"])
            with pytest.raises(SystemExit):
                run_cli(parsed)

    capture = capsys.readouterr()
    assert "Connection error" in capture.out
Ejemplo n.º 7
0
def test_target_case_equal_current_case(tmpdir):
    test_file = os.getenv('PYTEST_CURRENT_TEST')
    test_folder = os.path.dirname(test_file)
    data_folder = os.path.join(test_folder, '../../test-data/local')
    shutil.copytree(os.path.join(data_folder, 'poly_example'), os.path.join(str(tmpdir), 'poly_example'))
    with tmpdir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(parser, [ENSEMBLE_SMOOTHER_MODE, "--current-case", 'test_case',
                                    "--target-case", 'test_case',
                                    'poly_example/poly.ert'])
        

        with pytest.raises(SystemExit):
            run_cli(parsed)
Ejemplo n.º 8
0
def test_run_mocked_lsf_queue(poly_case_context):
    apply_customized_config()
    parser = ArgumentParser(prog="test_main")
    parsed = ert_parser(
        parser,
        [
            ENSEMBLE_EXPERIMENT_MODE,
            "poly_example/poly.ert",
            "--port-range",
            "1024-65535",
        ],
    )

    run_cli(parsed)
Ejemplo n.º 9
0
def test_cli_test_run(tmpdir, source_root, mock_cli_run):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )

    with tmpdir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(parser, [TEST_RUN_MODE, "poly_example/poly.ert"])
        run_cli(parsed)

    monitor_mock, thread_join_mock, thread_start_mock = mock_cli_run
    monitor_mock.assert_called_once()
    thread_join_mock.assert_called_once()
    thread_start_mock.assert_called_once()
Ejemplo n.º 10
0
def run_poly_example_new_storage(monkeypatch, tmpdir, source_root):
    poly_dir = py.path.local(os.path.join(str(tmpdir), "poly_example"))
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        poly_dir,
    )
    monkeypatch.setenv("ERT_STORAGE_NO_TOKEN", "yup")
    monkeypatch.setenv("ERT_STORAGE_RES_CONFIG", "poly.ert")
    monkeypatch.setenv("ERT_STORAGE_DATABASE_URL", "sqlite:///:memory:")

    from ert_storage.testing.testclient import testclient_factory

    with poly_dir.as_cwd(), testclient_factory(
    ) as ert_storage_client, dark_storage_app_(monkeypatch) as dark_app:
        new_storage_client_ = new_storage_client(monkeypatch,
                                                 ert_storage_client)

        from ert_shared.feature_toggling import FeatureToggling

        # Enable new storage
        feature = FeatureToggling._conf["new-storage"]
        monkeypatch.setattr(feature, "is_enabled", True)
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_SMOOTHER_MODE,
                "--target-case",
                "poly_runpath_file",
                "--realizations",
                "1,3,5",
                "poly.ert",
                "--port-range",
                "1024-65535",
            ],
        )
        run_cli(parsed)

        dark_storage_client_ = TestClient(dark_app)

        yield new_storage_client_, dark_storage_client_
Ejemplo n.º 11
0
def test_target_case_equal_current_case(tmpdir, source_root):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )
    with tmpdir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_SMOOTHER_MODE,
                "--current-case",
                "test_case",
                "--target-case",
                "test_case",
                "poly_example/poly.ert",
            ],
        )

        with pytest.raises(SystemExit):
            run_cli(parsed)
Ejemplo n.º 12
0
def poly_ran(request, source_root, tmp_path_factory):
    tmpdir = py.path.local(tmp_path_factory.mktemp("my_poly_tmp"))
    params = request.param
    params.update()

    poly_folder = make_poly_template(tmpdir, source_root, **params)
    params["folder"] = poly_folder

    with poly_folder.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_EXPERIMENT_MODE,
                "poly.ert",
                "--port-range",
                "1024-65535",
            ],
        )
        run_cli(parsed)

    yield params
Ejemplo n.º 13
0
def test_target_case_equal_current_case(tmpdir, source_root):
    shutil.copytree(
        os.path.join(source_root, "test-data", "local", "poly_example"),
        os.path.join(str(tmpdir), "poly_example"),
    )
    with tmpdir.as_cwd():
        parser = ArgumentParser(prog="test_main")
        parsed = ert_parser(
            parser,
            [
                ENSEMBLE_SMOOTHER_MODE,
                "--current-case",
                "test_case",
                "--target-case",
                "test_case",
                "poly_example/poly.ert",
                "--port-range",
                "1024-65535",
            ],
        )

        with pytest.raises(ErtCliError, match="They were both: test_case"):
            run_cli(parsed)