Example #1
0
def test_invalid_job(
    calc_key,
    app_key,
    obs_keys,
    obs_with_data,
    errors,
    alpha,
):
    user_config_dict = {
        "CALCULATE_KEYS": {"keys": [{"key": calc_key}], "std_cutoff": 0.001},
        "UPDATE_KEYS": {"keys": [{"key": app_key}]},
    }

    if alpha:
        user_config_dict["CALCULATE_KEYS"]["alpha"] = 3
    else:
        errors.insert(
            0,
            "MissingKeyError(msg=Missing key: alpha, "
            "key_path=('CALCULATE_KEYS',), layer=None)",
        )

    reporter = FileReporter(os.path.realpath(os.getcwd()))

    with pytest.raises(ValidationError) as exc_info:
        ScalingJob(obs_keys, [], obs_with_data, user_config_dict, reporter)
    assert [str(elem) for elem in exc_info.value.errors] == errors
Example #2
0
def test_invalid_job(
    calc_key,
    app_key,
    obs_keys,
    obs_with_data,
    errors,
):
    user_config_dict = {
        "CALCULATE_KEYS": {
            "keys": [{
                "key": calc_key
            }]
        },
        "UPDATE_KEYS": {
            "keys": [{
                "key": app_key
            }]
        },
    }

    reporter = FileReporter(os.path.realpath(os.getcwd()))

    with pytest.raises(ValidationError) as exc_info:
        ScalingJob(obs_keys, [], obs_with_data, user_config_dict, reporter)
    assert exc_info.value.errors == errors
Example #3
0
def test_valid_job(
    calc_key,
    app_key,
    obs_keys,
    obs_with_data,
    scaling_job_content,
):
    user_config_dict = {
        "CALCULATE_KEYS": {"keys": [{"key": calc_key}]},
        "UPDATE_KEYS": {"keys": [{"key": app_key}]},
    }
    default_vals = {
        "CALCULATE_KEYS": {"std_cutoff": 1.0e-6, "alpha": 3},
        "UPDATE_KEYS": {},
    }
    reporter = FileReporter(os.path.realpath(os.getcwd()))
    job = ScalingJob(
        obs_keys, [], obs_with_data, user_config_dict, reporter, default_vals
    )
    assert job.get_index_lists() == scaling_job_content["get_index_lists"]
    assert job.get_calc_keys() == scaling_job_content["get_calc_keys"]
Example #4
0
def test_valid_job(calc_key, app_key, obs_keys, obs_with_data, expect_valid,
                   errors):
    user_config_dict = {
        "CALCULATE_KEYS": {
            "keys": [{
                "key": calc_key
            }]
        },
        "UPDATE_KEYS": {
            "keys": [{
                "key": app_key
            }]
        },
    }
    if expect_valid:
        try:
            ScalingJob(obs_keys, [], obs_with_data, user_config_dict)
        except ValidationError as e:
            pytest.fail("unexpectedly raised ValidationError: {}".format(e))
    else:
        with pytest.raises(ValidationError) as exc_info:
            ScalingJob(obs_keys, [], obs_with_data, user_config_dict)
        assert exc_info.value.errors == errors
Example #5
0
def test_config_value_overwrites_default(input_key):
    user_config_dict = {
        "CALCULATE_KEYS": {"keys": [{"key": "a_key"}], "alpha": 2, "std_cutoff": 0.01},
    }
    default_vals = {
        "CALCULATE_KEYS": {"std_cutoff": 1.0e-6, "alpha": 3},
        "UPDATE_KEYS": {},
    }
    reporter = FileReporter(os.path.realpath(os.getcwd()))
    job = ScalingJob(["a_key"], [], ["a_key"], user_config_dict, reporter, default_vals)

    # Check that the value equals the config value
    assert (
        getattr(job._config.snapshot.CALCULATE_KEYS, input_key)
        == user_config_dict["CALCULATE_KEYS"][input_key]
    )
    # Check that different from default value
    assert (
        getattr(job._config.snapshot.CALCULATE_KEYS, input_key)
        != default_vals["CALCULATE_KEYS"][input_key]
    )
    def run(self, job_config):
        facade = LibresFacade(self.ert())
        user_config = load_yaml(job_config)
        user_config = _insert_default_group(user_config)

        obs = facade.get_observations()
        obs_keys = [facade.get_observation_key(nr) for nr, _ in enumerate(obs)]
        obs_with_data = keys_with_data(
            obs,
            obs_keys,
            facade.get_ensemble_size(),
            facade.get_current_fs(),
        )

        for config in user_config:
            job = ScalingJob(obs_keys, obs, obs_with_data, config)
            measured_data = MeasuredData(facade, job.get_calc_keys(),
                                         job.get_index_lists())
            job.scale(measured_data)