Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 3
0
class _ReportHandler(BufferingHandler):
    def __init__(self, output_dir):
        super(_ReportHandler, self).__init__(1)
        self._reporter = FileReporter(output_dir)
        self._namespace = SEMEIOSCRIPT_LOG_FILE

    def flush(self):
        for log_record in self.buffer:
            self._reporter.publish_msg(self._namespace,
                                       self._format_record(log_record))

        super(_ReportHandler, self).flush()

    def _format_record(self, log_record):
        log_fmt = "{log_level} [{log_time}]: {log_message}"
        return log_fmt.format(
            log_level=log_record.levelname,
            log_time=datetime.datetime.fromtimestamp(log_record.created),
            log_message=log_record.message,
        )
Ejemplo n.º 4
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]
    )
Ejemplo n.º 5
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"]
Ejemplo n.º 6
0
 def __init__(self, ert):
     super().__init__(ert)
     self._output_dir = self._get_output_dir()
     self._reporter = FileReporter(self._output_dir)
     self._wrap_run()
Ejemplo n.º 7
0
 def __init__(self, output_dir, thread_id):
     super().__init__(1)
     self._reporter = FileReporter(output_dir)
     self._namespace = SEMEIOSCRIPT_LOG_FILE
     self.addFilter(lambda rec: rec.thread == thread_id)
Ejemplo n.º 8
0
 def __init__(self, output_dir):
     super(_ReportHandler, self).__init__(1)
     self._reporter = FileReporter(output_dir)
     self._namespace = SEMEIOSCRIPT_LOG_FILE
Ejemplo n.º 9
0
 def __init__(self, output_dir):
     super(_ReportHandler, self).__init__(1)
     self._reporter = FileReporter(output_dir)
     self._namespace = "log.txt"