Esempio n. 1
0
def test_serialize_scheduled_state_with_context():
    with prefect.context(task_run_count=42):
        s = state.Scheduled(message="hi")

    serialized = StateSchema().dump(s)
    assert isinstance(serialized, dict)
    assert serialized["type"] == "Scheduled"
    assert serialized["message"] == "hi"
    assert serialized["__version__"] == prefect.__version__
    assert serialized["context"] == dict(task_run_count=42)

    deserialized = StateSchema().load(serialized)
    assert deserialized.is_scheduled()
    assert deserialized.context == dict(task_run_count=42)
    assert set(deserialized.context["tags"]) == set(["foo", "bar"])


def test_serialize_scheduled_state_with_context():
    with prefect.context(task_run_count=42):
        s = state.Scheduled(message="hi")

    serialized = StateSchema().dump(s)
    assert isinstance(serialized, dict)
    assert serialized["type"] == "Scheduled"
    assert serialized["message"] == "hi"
    assert serialized["__version__"] == prefect.__version__
    assert serialized["context"] == dict(task_run_count=42)

    deserialized = StateSchema().load(serialized)
    assert deserialized.is_scheduled()
    assert deserialized.context == dict(task_run_count=42)


def test_serialize_state_with_context_allows_for_diverse_values():
    s = state.Running(message="hi")
    s.context = dict(tags=["foo", "bar"], info=dict(x=42), baz="99")
    serialized = StateSchema().dump(s)
    assert isinstance(serialized, dict)
    assert serialized["type"] == "Running"
    assert serialized["message"] == "hi"
    assert serialized["__version__"] == prefect.__version__
    assert serialized["context"] == s.context

    deserialized = StateSchema().load(serialized)
    assert deserialized.is_running()