def complex_states(): res1 = SafeResult(1, result_handler=JSONResultHandler()) res2 = SafeResult({"z": 2}, result_handler=JSONResultHandler()) res3 = SafeResult(dict(x=1, y={"z": 2}), result_handler=JSONResultHandler()) naive_dt = datetime.datetime(2020, 1, 1) utc_dt = pendulum.datetime(2020, 1, 1) complex_result = {"x": res1, "y": res2} cached_state = state.Cached( cached_inputs=complex_result, result=res3, cached_parameters={ "x": 1, "y": { "z": 2 } }, cached_result_expiration=utc_dt, ) cached_state_naive = state.Cached( cached_inputs=complex_result, result=res3, cached_parameters={ "x": 1, "y": { "z": 2 } }, 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.Pending(cached_inputs=complex_result), state.Paused(cached_inputs=complex_result), 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, state.TimedOut(cached_inputs=complex_result), ] return test_states
class TestInitializeRun: def test_initialize_run_returns_state_and_context(self): state_, context = state.Pending(), {} s, c = Runner().initialize_run(state=state_, context=context) assert s is state_ assert c is context @pytest.mark.parametrize( "state", [ state.Success(), state.Failed(), state.Pending(), state.Scheduled(), state.Skipped(), state.Cached(), state.Retrying(), state.Running(), ], ) def test_initialize_run_returns_state(self, state): new_state, _ = Runner().initialize_run(state, context={}) assert new_state is state @pytest.mark.parametrize( "state", [ state.Submitted(state=state.Pending()), state.Submitted(state=state.Retrying()), state.Submitted(state=state.Scheduled()), state.Submitted(state=state.Resume()), state.Queued(state=state.Pending()), state.Queued(state=state.Retrying()), state.Queued(state=state.Scheduled()), state.Queued(state=state.Resume()), ], ) def test_initialize_run_gets_wrapped_state_from_submitted_states( self, state): new_state, _ = Runner().initialize_run(state, context={}) assert new_state is state.state def test_initialize_run_creates_pending_if_no_state_provided(self): new_state, _ = Runner().initialize_run(state=None, context={}) assert isinstance(new_state, state.Pending)
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
state.Looped(loop_count=45), <<<<<<< HEAD ======= state.Pending(cached_inputs=complex_result), state.Paused(cached_inputs=complex_result), >>>>>>> prefect clone 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, <<<<<<< HEAD ======= state.TimedOut(cached_inputs=complex_result), >>>>>>> prefect clone ] return test_states def test_all_states_have_serialization_schemas_in_stateschema(): """ Tests that all State subclasses in prefect.engine.states have corresponding schemas