예제 #1
0
def test_serialize_k8s_job_env_with_job_spec(k8s_job_spec_content):
    with tempfile.TemporaryDirectory() as directory:
        with open(os.path.join(directory, "job.yaml"), "w+") as f:
            f.write(k8s_job_spec_content)

        env = environments.KubernetesJobEnvironment(
            job_spec_file=os.path.join(directory, "job.yaml"))

        schema = KubernetesJobEnvironmentSchema()
        serialized = schema.dump(env)

        deserialized = schema.load(serialized)
        assert isinstance(deserialized, environments.KubernetesJobEnvironment)
예제 #2
0
def test_serialize_k8s_job_environment_with_labels():
    with tempfile.TemporaryDirectory() as directory:

        with open(os.path.join(directory, "job.yaml"), "w+") as file:
            file.write("job")

        env = environments.KubernetesJobEnvironment(job_spec_file=os.path.join(
            directory, "job.yaml"),
                                                    labels=["a", "b", "c"])

        schema = KubernetesJobEnvironmentSchema()
        serialized = schema.dump(env)
        assert serialized
        assert serialized["__version__"] == prefect.__version__
        assert set(serialized["labels"]) == set(["a", "b", "c"])

    new = schema.load(serialized)
    assert new.labels == set(["a", "b", "c"])
예제 #3
0
def test_serialize_k8s_job_environment_with_labels(k8s_job_spec_content):
    with tempfile.TemporaryDirectory() as directory:

        with open(os.path.join(directory, "job.yaml"), "w+") as file:
            file.write(k8s_job_spec_content)

        env = environments.KubernetesJobEnvironment(job_spec_file=os.path.join(
            directory, "job.yaml"),
                                                    labels=["b", "c", "a"])

        schema = KubernetesJobEnvironmentSchema()
        serialized = schema.dump(env)
        assert serialized
        assert serialized["__version__"] == prefect.__version__
        # labels should be sorted in the serialized obj
        assert serialized["labels"] == ["a", "b", "c"]

    new = schema.load(serialized)
    assert new.labels == {"a", "b", "c"}
예제 #4
0
def test_serialize_k8s_job_environment(k8s_job_spec_content):
    with tempfile.TemporaryDirectory() as directory:

        with open(os.path.join(directory, "job.yaml"), "w+") as file:
            file.write(k8s_job_spec_content)

        env = environments.KubernetesJobEnvironment(
            job_spec_file=os.path.join(directory, "job.yaml"))

        schema = KubernetesJobEnvironmentSchema()
        serialized = schema.dump(env)
        assert serialized
        assert serialized["__version__"] == prefect.__version__
        assert serialized["labels"] == []
        assert serialized["metadata"] == {}

    new = schema.load(serialized)
    assert new.labels == set()
    assert new.job_spec_file is None