Skip to content

Commit

Permalink
fixup: move conditional validation to decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-eq committed Sep 24, 2024
1 parent 5ca6ebf commit e1ccde3
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/semeio/forward_models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional
from typing import Callable, Optional

from ert import (
ForwardModelStepDocumentation,
Expand All @@ -11,6 +11,16 @@
from .scripts.design_kw import design_kw as DesignKWScript


def validation_enabled(validation_func: Callable) -> Callable[..., None]:
def wrapper(
self: ForwardModelStepPlugin, fm_step_json: ForwardModelStepJSON
) -> None:
if self.private_args.get("<VALIDATE>", "").lower() == "true":
validation_func(self, fm_step_json)

return wrapper


class Design2Params(ForwardModelStepPlugin):
def __init__(self):
super().__init__(
Expand Down Expand Up @@ -55,12 +65,11 @@ def validate_pre_realization_run(
) -> ForwardModelStepJSON:
return fm_step_json

@validation_enabled
def validate_pre_experiment(self, fm_step_json: ForwardModelStepJSON) -> None:
should_fail_on_validation_error = (
fm_step_json.get("argList")[2].lower() == "true"
)
if should_fail_on_validation_error:
DesignKWScript.validate_configuration(fm_step_json.get("argList")[0])
template_file_name = self.private_args["<template_file>"]
DesignKWScript.validate_configuration(template_file_name=template_file_name)
return fm_step_json

@staticmethod
def documentation() -> Optional[ForwardModelStepDocumentation]:
Expand Down

0 comments on commit e1ccde3

Please sign in to comment.