Exemple #1
0
 def test_handles_none(self):
     state = Cached(cached_inputs=dict(x=5))
     assert (partial_parameters_only(validate_on=["x"])(state, None,
                                                        dict(x=5)) is False)
     state = Cached(cached_parameters=dict(x=5))
     assert partial_parameters_only(validate_on=["x"])(state, None,
                                                       None) is False
Exemple #2
0
 def test_parameters_validate_with_defaults(self):
     state = Cached(cached_parameters=dict(x=1, s="str"))
     assert partial_parameters_only()(state, None, dict(x=1,
                                                        s="str")) is True
     state = Cached(cached_parameters=dict(x=1, s="str"))
     assert partial_parameters_only()(state, None, dict(x=1,
                                                        s="strs")) is True
Exemple #3
0
 def test_validate_on_kwarg(self):
     state = Cached(cached_parameters=dict(x=1, s="str"))
     assert (partial_parameters_only(validate_on=["x", "s"])(
         state, None, dict(x=1, s="str")) is True)
     state = Cached(cached_parameters=dict(x=1, s="str"))
     assert (partial_parameters_only(validate_on=["x", "s"])(
         state, None, dict(x=1, s="strs")) is False)
     assert (partial_parameters_only(validate_on=["x"])(
         state, None, dict(x=1, s="strs")) is True)
     assert (partial_parameters_only(validate_on=["s"])(
         state, None, dict(x=1, s="strs")) is False)
Exemple #4
0
from prefect import task, Flow, Parameter
from prefect.engine.cache_validators import partial_parameters_only
from prefect.environments.execution import RemoteEnvironment
from prefect.environments.storage import Docker
from prefect.engine.result_handlers import JSONResultHandler, S3ResultHandler
from prefect.tasks.shell import ShellTask


@task(max_retries=5, retry_delay=datetime.timedelta(minutes=10))
def root_task():
    pass


@task(
    cache_for=datetime.timedelta(days=10),
    cache_validator=partial_parameters_only(["x"]),
    result_handler=JSONResultHandler(),
)
def cached_task(x, y):
    pass


x = Parameter("x")
y = Parameter("y", default=42)


@task(name="Big Name",
      checkpoint=True,
      result_handler=S3ResultHandler(bucket="blob"))
def terminal_task():
    pass
Exemple #5
0
 def test_curried(self):
     state = Cached(cached_parameters=dict(x=1, s="str"))
     validator = partial_parameters_only(validate_on=["x"])
     assert validator(state, None, dict(x=1)) is True
     assert validator(state, None, dict(x=2, s="str")) is False