def test_cached_inputs_are_serialized_correctly(self): s = state.Cached( message="test", result=results.PrefectResult(value=1, location="1"), cached_inputs=dict( x=results.PrefectResult(location='"foo"'), y=results.PrefectResult(location='"bar"'), ), )
def test_cached_inputs_are_serialized_correctly(self): s = state.Cached( message="test", result=results.PrefectResult(value=1, location="1"), cached_inputs=dict( x=results.PrefectResult(location='"foo"'), y=results.PrefectResult(location='"bar"'), ), ) schema = StateSchema() serialized = schema.dump(s) assert serialized["cached_inputs"]["x"]["location"] == '"foo"' assert serialized["cached_inputs"]["y"]["location"] == '"bar"' new_state = schema.load(serialized) assert new_state.cached_inputs["x"].location == '"foo"' assert new_state.cached_inputs["y"].location == '"bar"'
def test_prefect_result(): schema = StateResultSchema() result = results.PrefectResult(value=42, location="42") serialized = schema.dump(result) assert serialized["type"] == "PrefectResult" assert "value" not in serialized assert serialized["location"] == "42" new_result = schema.load(serialized) assert isinstance(new_result, results.PrefectResult) assert new_result.location == "42" assert new_result.value is None
def complex_states(): res1 = results.PrefectResult(value=1) res2 = results.PrefectResult(value={"z": 2}) res3 = results.PrefectResult(location=json.dumps(dict(x=1, y={"z": 2}))) naive_dt = datetime.datetime(2020, 1, 1) utc_dt = pendulum.datetime(2020, 1, 1) cached_state = state.Cached( hashed_inputs=dict(x="foo", y="bar"), result=res3, cached_result_expiration=utc_dt, ) cached_state_naive = state.Cached( hashed_inputs=dict(x="foo", y="bar"), result=res3, cached_result_expiration=naive_dt, ) running_tags = state.Running() running_tags.context = dict(tags=["1", "2", "3"]) test_states = [ state.Looped(loop_count=45), state.Retrying(start_time=utc_dt, run_count=3), state.Retrying(start_time=naive_dt, run_count=3), state.Scheduled(start_time=utc_dt), state.Scheduled(start_time=naive_dt), state.Resume(start_time=utc_dt), state.Resume(start_time=naive_dt), running_tags, state.Submitted(state=state.Retrying(start_time=utc_dt, run_count=2)), state.Submitted(state=state.Resume(start_time=utc_dt)), state.Queued(state=state.Pending()), state.Queued(state=state.Pending(), start_time=utc_dt), state.Queued(state=state.Retrying(start_time=utc_dt, run_count=2)), cached_state, cached_state_naive, ] return test_states
set( cls for cls in state.__dict__.values() if isinstance(cls, type) and issubclass(cls, state.State) and cls not in (state.State, state._MetaState) ), key=lambda c: c.__name__, ) from marshmallow import Schema def complex_states(): <<<<<<< HEAD res1 = results.PrefectResult(value=1) res2 = results.PrefectResult(value={"z": 2}) res3 = results.PrefectResult(location=json.dumps(dict(x=1, y={"z": 2}))) naive_dt = datetime.datetime(2020, 1, 1) utc_dt = pendulum.datetime(2020, 1, 1) cached_state = state.Cached( hashed_inputs=dict(x="foo", y="bar"), result=res3, cached_result_expiration=utc_dt, ) cached_state_naive = state.Cached( hashed_inputs=dict(x="foo", y="bar"), result=res3, ======= res1 = SafeResult(1, result_handler=JSONResultHandler()) res2 = SafeResult({"z": 2}, result_handler=JSONResultHandler())