Exemplo n.º 1
0
def test_safe_result_with_custom_handler_deserializes():
    r = SafeResultSchema().load(
        {"value": "3", "result_handler": {"type": "CustomResultHandler"}}
    )
    assert isinstance(r, SafeResult)
    assert r.value == "3"
    assert isinstance(r.result_handler, ResultHandler)
Exemplo n.º 2
0
def test_basic_safe_result_deserializes():
    r = SafeResultSchema().load(
        {"value": "3", "result_handler": {"type": "JSONResultHandler"}}
    )
    assert isinstance(r, SafeResult)
    assert r.value == "3"
    assert r.result_handler == JSONResultHandler()
Exemplo n.º 3
0
def test_safe_result_disallows_none_result_handler_at_deserialization_time():
    schema = SafeResultSchema()
    r = SafeResult(value=None, result_handler=None)
    serialized = schema.dump(r)
    with pytest.raises(marshmallow.exceptions.ValidationError):
        schema.load(serialized)
Exemplo n.º 4
0
def test_result_allows_none_value():
    schema = SafeResultSchema()
    r = SafeResult(value=None, result_handler=JSONResultHandler())
    handled = schema.load(schema.dump(r))
    assert handled.value is None
    assert handled.result_handler == JSONResultHandler()
Exemplo n.º 5
0
def test_safe_result_serializes_result_handlers():
    r = SafeResult(value=3, result_handler=JSONResultHandler())
    handled = SafeResultSchema().dump(r)
    assert handled["result_handler"]["type"] == "JSONResultHandler"
Exemplo n.º 6
0
def test_roundtrip_for_results():
    r = SafeResult(value={"y": 4}, result_handler=JSONResultHandler())
    s = SafeResultSchema().load(SafeResultSchema().dump(r))
    assert r == s
Exemplo n.º 7
0
def test_basic_safe_result_serializes():
    res = SafeResult("3", result_handler=JSONResultHandler())
    serialized = SafeResultSchema().dump(res)
    assert serialized["__version__"] == prefect.__version__
    assert serialized["value"] == "3"
    assert serialized["result_handler"]["type"] == "JSONResultHandler"