Ejemplo n.º 1
0
 def test_argparse_exec_ensemble_smoother_default_target_case(self):
     parser = ArgumentParser(prog="test_main")
     with self.assertRaises(SystemExit):
         ert_parser(parser, [
             'ensemble_smoother', "--target-case", 'default',
             'test-data/local/poly_example/poly.ert'
         ])
Ejemplo n.º 2
0
 def test_argparse_exec_ensemble_experiment_faulty_realizations(self):
     parser = ArgumentParser(prog="test_main")
     with self.assertRaises(SystemExit):
         ert_parser(parser, [
             ENSEMBLE_EXPERIMENT_MODE, "--realizations", "1~4,7,"
             'test-data/local/poly_example/poly.ert'
         ])
Ejemplo n.º 3
0
def test_version_valid_Version(capsys):

    try:
        ert_parser(None, ["--version"])
    except SystemExit as e:
        assert e.code == 0

    ert_version, _ = capsys.readouterr()
    ert_version = ert_version.rstrip("\n")

    assert Version(ert_version)
Ejemplo n.º 4
0
def test_argparse_exec_ensemble_experiment_faulty_realizations():
    with pytest.raises(SystemExit):
        ert_parser(
            None,
            [
                ENSEMBLE_EXPERIMENT_MODE,
                "--realizations",
                "1~4,7,",
                "path/to/config.ert",
            ],
        )
Ejemplo n.º 5
0
def test_version_mocked(capsys, monkeypatch):
    monkeypatch.setattr(ert_shared, "__version__", "1.0.3")

    try:
        ert_parser(None, ["--version"])
    except SystemExit as e:
        assert e.code == 0

    ert_version, _ = capsys.readouterr()
    ert_version = ert_version.rstrip("\n")

    assert ert_version == "1.0.3"
Ejemplo n.º 6
0
def test_argparse_invalid_port_range(port_input, ):
    with pytest.raises(SystemExit):

        ert_parser(
            None,
            [
                ENSEMBLE_EXPERIMENT_MODE,
                "--port-range",
                port_input,
                "path/to/config.ert",
            ],
        )
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
0
def test_argparse_exec_ensemble_es_mda_current_case():
    parsed = ert_parser(
        None,
        [ES_MDA_MODE, "--current-case", "test_case", "path/to/config.ert"])
    assert parsed.mode == ES_MDA_MODE
    assert parsed.current_case == "test_case"
    assert parsed.func.__name__ == "run_cli"
Ejemplo n.º 13
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.º 14
0
def test_argparse_exec_ensemble_experiment_current_case():
    parsed = ert_parser(
        None,
        [ENSEMBLE_EXPERIMENT_MODE, "--current-case", "test_case", "path/to/config.ert"],
    )
    assert parsed.mode == ENSEMBLE_EXPERIMENT_MODE
    assert parsed.current_case == "test_case"
    assert parsed.func.__name__ == "run_cli"
Ejemplo n.º 15
0
def test_argparse_exec_ensemble_smoother_valid_case():
    parsed = ert_parser(
        None,
        [ENSEMBLE_SMOOTHER_MODE, "--target-case", "some_case", "path/to/config.ert"],
    )
    assert parsed.mode == ENSEMBLE_SMOOTHER_MODE
    assert parsed.target_case == "some_case"
    assert parsed.func.__name__ == "run_cli"
Ejemplo n.º 16
0
def test_argparse_exec_ensemble_experiment_valid_case():
    parsed = ert_parser(
        None,
        [ENSEMBLE_EXPERIMENT_MODE, "--realizations", "1-4,7,8", "path/to/config.ert"],
    )
    assert parsed.mode == ENSEMBLE_EXPERIMENT_MODE
    assert parsed.realizations == "1-4,7,8"
    assert parsed.func.__name__ == "run_cli"
Ejemplo n.º 17
0
def test_argparse_no_port_range():
    parsed = ert_parser(
        None,
        [
            ENSEMBLE_EXPERIMENT_MODE,
            "path/to/config.ert",
        ],
    )
    assert parsed.port_range == None
Ejemplo n.º 18
0
 def test_argparse_exec_es_mda_default_weights(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(
         parser, [ES_MDA_MODE, 'test-data/local/poly_example/poly.ert'])
     self.assertEquals(parsed.mode, ES_MDA_MODE)
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.weights, "4, 2, 1")
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertFalse(parsed.verbose)
Ejemplo n.º 19
0
 def test_argparse_exec_test_run_valid_case(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(parser, [
         TEST_RUN_MODE, "--verbose", 'test-data/local/poly_example/poly.ert'
     ])
     self.assertEquals(parsed.mode, TEST_RUN_MODE)
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertTrue(parsed.verbose)
Ejemplo n.º 20
0
def test_argparse_valid_port_range(port_input, expected_range):
    parsed = ert_parser(
        None,
        [
            ENSEMBLE_EXPERIMENT_MODE,
            "--port-range",
            port_input,
            "path/to/config.ert",
        ],
    )
    assert parsed.port_range == expected_range
Ejemplo n.º 21
0
 def test_argparse_exec_ensemble_es_mda_current_case(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(parser, [
         ES_MDA_MODE, "--current-case", 'test_case',
         'test-data/local/poly_example/poly.ert'
     ])
     self.assertEquals(parsed.mode, ES_MDA_MODE)
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.current_case, 'test_case')
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertFalse(parsed.verbose)
Ejemplo n.º 22
0
 def test_argparse_exec_ensemble_experiment_valid_case(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(parser, [
         ENSEMBLE_EXPERIMENT_MODE, "--realizations", "1-4,7,8",
         'test-data/local/poly_example/poly.ert'
     ])
     self.assertEquals(parsed.mode, ENSEMBLE_EXPERIMENT_MODE)
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.realizations, "1-4,7,8")
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertFalse(parsed.verbose)
Ejemplo n.º 23
0
 def test_argparse_exec_ensemble_smoother_valid_case(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(parser, [
         ENSEMBLE_SMOOTHER_MODE, "--target-case", "some_case",
         'test-data/local/poly_example/poly.ert'
     ])
     self.assertEquals(parsed.mode, ENSEMBLE_SMOOTHER_MODE)
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.target_case, "some_case")
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertFalse(parsed.verbose)
Ejemplo n.º 24
0
 def test_argparse_exec_workflow(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(parser, [
         WORKFLOW_MODE, "--verbose", "workflow_name",
         'test-data/local/poly_example/poly.ert'
     ])
     self.assertEquals(parsed.mode, WORKFLOW_MODE)
     self.assertEquals(parsed.name, "workflow_name")
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertTrue(parsed.verbose)
Ejemplo n.º 25
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.º 26
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.º 27
0
def test_argparse_exec_iterative_ensemble_smoother_current_case():
    parsed = ert_parser(
        None,
        [
            ITERATIVE_ENSEMBLE_SMOOTHER_MODE,
            "--current-case",
            "test_case",
            "--target-case",
            "test_case_smoother_%d",
            "path/to/config.ert",
        ],
    )
    assert parsed.mode == ITERATIVE_ENSEMBLE_SMOOTHER_MODE
    assert parsed.current_case == "test_case"
    assert parsed.func.__name__ == "run_cli"
Ejemplo n.º 28
0
 def test_argparse_exec_es_mda_valid_case(self):
     parser = ArgumentParser(prog="test_main")
     parsed = ert_parser(parser, [
         ES_MDA_MODE, "--target-case", "some_case%d", "--realizations",
         "1-10", "--verbose", "--weights", "1, 2, 4",
         'test-data/local/poly_example/poly.ert'
     ])
     self.assertEquals(parsed.mode, ES_MDA_MODE)
     self.assertEquals(parsed.config,
                       "test-data/local/poly_example/poly.ert")
     self.assertEquals(parsed.target_case, "some_case%d")
     self.assertEquals(parsed.realizations, "1-10")
     self.assertEquals(parsed.weights, "1, 2, 4")
     self.assertEquals(parsed.func.__name__, "run_cli")
     self.assertTrue(parsed.verbose)
Ejemplo n.º 29
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.º 30
0
def test_argparse_exec_es_mda_valid_case():
    parsed = ert_parser(
        None,
        [
            ES_MDA_MODE,
            "--target-case",
            "some_case%d",
            "--realizations",
            "1-10",
            "--weights",
            "1, 2, 4",
            "path/to/config.ert",
        ],
    )
    assert parsed.mode == ES_MDA_MODE
    assert parsed.target_case == "some_case%d"
    assert parsed.realizations == "1-10"
    assert parsed.weights == "1, 2, 4"
    assert parsed.func.__name__ == "run_cli"