Exemple #1
0
def test_deserialize_old_env_payload():
    old = {
        "executor": "prefect.engine.executors.LocalExecutor",
        "executor_kwargs": {},
        "__version__": "0.6.3",
        "type": "RemoteEnvironment",
    }

    schema = EnvironmentSchema()
    obj = schema.load(old)
    assert isinstance(obj, environments.RemoteEnvironment)
    assert obj.labels == set()
Exemple #2
0
def test_deserialize_old_environments_still_work(cls_name):
    """Check that old removed environments can still be deserialzed in the agent"""
    env = {
        "type": cls_name,
        "labels": ["prod"],
        "executor": "prefect.engine.executors.LocalExecutor",
        "__version__": "0.9.0",
        "executor_kwargs": {},
    }
    schema = EnvironmentSchema()
    obj = schema.load(env)

    assert isinstance(obj, environments.Environment)
    assert obj.labels == {"prod"}
    assert obj.metadata == {}
Exemple #3
0
def test_serialize_custom_environment():
    class MyEnv(environments.Environment):
        def __init__(self, x=5):
            self.x = 5
            super().__init__(labels=["foo", "bar"])

        def custom_method(self):
            pass

    env = MyEnv()
    schema = EnvironmentSchema()
    serialized = schema.dump(env)
    assert serialized["type"] == "CustomEnvironment"
    assert set(serialized["labels"]) == set(["foo", "bar"])

    obj = schema.load(serialized)
    assert isinstance(obj, environments.Environment)
    assert obj.labels == set(["foo", "bar"])
def test_serialize_custom_environment():
    class MyEnv(environments.Environment):
        def __init__(self, x=5):
            self.x = 5
            super().__init__(labels=["b", "c", "a"], metadata={"test": "here"})

        def custom_method(self):
            pass

    env = MyEnv()
    schema = EnvironmentSchema()
    serialized = schema.dump(env)
    assert serialized["type"] == "CustomEnvironment"
    assert serialized["labels"] == ["a", "b", "c"]
    assert serialized["metadata"] == {"test": "here"}

    obj = schema.load(serialized)
    assert isinstance(obj, environments.Environment)
    assert obj.labels == {"a", "b", "c"}
    assert obj.metadata == {"test": "here"}