Exemplo n.º 1
0
 def test_cloud_can_deserialize_custom_handlers(self):
     schema = ResultHandlerSchema()
     serialized = {
         "type": "CustomResultHandler",
         "__version__": "0.6.3+120.g60ca943b",
     }
     assert schema.load(serialized) is None
Exemplo n.º 2
0
 def test_deserialize_local_result_handler(self, dir):
     schema = ResultHandlerSchema()
     obj = schema.load(schema.dump(LocalResultHandler(dir=dir)))
     assert isinstance(obj, LocalResultHandler)
     assert hasattr(obj, "logger")
     assert obj.logger.name == "prefect.LocalResultHandler"
     assert obj.dir == dir
Exemplo n.º 3
0
 def test_deserialize_cloud_result_handler(self):
     schema = ResultHandlerSchema()
     handler = CloudResultHandler(result_handler_service="http://foo.bar")
     handler._client = Client()
     obj = schema.load(schema.dump(handler))
     assert isinstance(obj, CloudResultHandler)
     assert hasattr(obj, "logger")
     assert obj.logger.name == "prefect.CloudResultHandler"
     assert obj.result_handler_service == "http://foo.bar"
     assert obj._client is None
Exemplo n.º 4
0
    def test_roundtrip_never_loads_client(self, monkeypatch):
        schema = ResultHandlerSchema()

        def raise_me(*args, **kwargs):
            raise SyntaxError("oops")

        monkeypatch.setattr(GCSResultHandler, "initialize_client", raise_me)
        handler = schema.load(
            schema.dump(
                GCSResultHandler(bucket="bucket3", credentials_secret="FOO")))
        assert isinstance(handler, GCSResultHandler)
        assert handler.bucket == "bucket3"
        assert handler.credentials_secret == "FOO"
Exemplo n.º 5
0
 def test_deserialize_cloud_result_handler_with_None_populates_from_config(self):
     schema = ResultHandlerSchema()
     handler = CloudResultHandler()
     handler.result_handler_service = None
     handler._client = Client()
     serialized = schema.dump(handler)
     with set_temporary_config({"cloud.result_handler": "new-service"}):
         obj = schema.load(serialized)
     assert isinstance(obj, CloudResultHandler)
     assert hasattr(obj, "logger")
     assert obj.logger.name == "prefect.CloudResultHandler"
     assert obj.result_handler_service == "new-service"
     assert obj._client is None
Exemplo n.º 6
0
    def test_roundtrip_never_loads_client(self, monkeypatch):
        schema = ResultHandlerSchema()

        def raise_me(*args, **kwargs):
            raise SyntaxError("oops")

        monkeypatch.setattr(AzureResultHandler, "initialize_service", raise_me)
        handler = schema.load(
            schema.dump(
                AzureResultHandler(container="container3",
                                   azure_credentials_secret="FOO")))
        assert isinstance(handler, AzureResultHandler)
        assert handler.container == "container3"
        assert handler.azure_credentials_secret == "FOO"
Exemplo n.º 7
0
    def test_result_handler_schema_defaults_to_custom(self):
        class Weird(ResultHandler):
            def __init__(self, y):
                self.y = y

            def read(self, *args, **kwargs):
                return 99

            def write(self, *args, **kwargs):
                return type(None)

        schema = ResultHandlerSchema()
        serialized = schema.dump(Weird(dict(y="test")))
        assert serialized["type"].endswith("Weird")
        assert serialized["__version__"] == prefect.__version__

        obj = schema.load(serialized)
        assert obj is None
Exemplo n.º 8
0
    def test_result_handler_schema_defaults_to_custom(self):
        class Weird(ResultHandler):
            def __init__(self, y):
                self.y = y

            def read(self, *args, **kwargs):
                return 99

            def write(self, *args, **kwargs):
                return type(None)

        schema = ResultHandlerSchema()
        serialized = schema.dump(Weird(dict(y="test")))
        assert serialized["type"] == "CustomResultHandler"
        assert serialized["__version__"] == prefect.__version__

        obj = schema.load(serialized)
        assert isinstance(obj, ResultHandler)
        assert obj.write("foo") is None  # just the base class, not the Weird class
Exemplo n.º 9
0
 def test_roundtrip(self):
     schema = ResultHandlerSchema()
     handler = schema.load(schema.dump(S3ResultHandler(bucket="bucket3")))
     assert isinstance(handler, S3ResultHandler)
     assert handler.bucket == "bucket3"
Exemplo n.º 10
0
 def test_roundtrip(self):
     schema = ResultHandlerSchema()
     handler = schema.load(schema.dump(JSONResultHandler()))
     assert isinstance(handler, JSONResultHandler)
     assert handler.write(3) == "3"
Exemplo n.º 11
0
 def test_roundtrip(self, google_client):
     schema = ResultHandlerSchema()
     handler = schema.load(schema.dump(GCSResultHandler(bucket="bucket3")))
     assert isinstance(handler, GCSResultHandler)
     assert handler.bucket == "bucket3"
Exemplo n.º 12
0
 def test_roundtrip(self):
     schema = ResultHandlerSchema()
     handler = schema.load(
         schema.dump(AzureResultHandler(container="container3")))
     assert isinstance(handler, AzureResultHandler)
     assert handler.container == "container3"