def test_serialize_adds_flow_to_storage_if_build(self): f = Flow(name="test", storage=prefect.environments.storage.Memory()) s_no_build = f.serialize() assert f.name not in f.storage s_build = f.serialize(build=True) assert f.name in f.storage
def test_serialize_includes_storage(self): f = Flow(name="test", storage=prefect.environments.storage.Memory()) s_no_build = f.serialize() s_build = f.serialize(build=True) assert s_no_build["storage"]["type"] == "Memory" assert s_build["storage"]["type"] == "Memory"
def test_serialize_can_be_called_twice(self): f = Flow(name="test", storage=prefect.environments.storage.Memory()) s_no_build = f.serialize() assert f.name not in f.storage f.serialize(build=True) f.serialize(build=True)
def test_serialize_includes_environment(self): f = Flow(name="test", environment=prefect.environments.LocalEnvironment()) s_no_build = f.serialize() s_build = f.serialize(build=True) assert s_no_build["environment"]["type"] == "LocalEnvironment" assert s_no_build["environment"]["serialized_flow"] is None assert s_build["environment"]["type"] == "LocalEnvironment"
def test_serialize_validates_invalid_flows(self): t1, t2 = Task(), Task() f = Flow(name="test") f.add_edge(t1, t2) # default settings should allow this even though it's illegal f.add_edge(t2, t1) with pytest.raises(ValueError) as exc: f.serialize() assert "cycle found" in str(exc).lower()
def test_serialize_can_be_called_twice(self): f = Flow(name="test", storage=prefect.environments.storage.Memory()) s_no_build = f.serialize() assert f.name not in f.storage f.serialize(build=True) with pytest.warns(UserWarning) as warning: f.serialize(build=True) w = warning.pop() assert "already contained in storage" in str(w.message)
def test_serialization(self): p1, t2, t3, = Parameter("1"), Task("2"), Task("3") f = Flow(name="test", tasks=[p1, t2, t3]) f.add_edge(p1, t2) f.add_edge(p1, t3) serialized = f.serialize() assert isinstance(serialized, dict) assert len(serialized["tasks"]) == len(f.tasks)
def test_deserialization(self): p1, t2, t3, = Parameter("1"), Task("2"), Task("3") f = Flow( name="hi", tasks=[p1, t2, t3], schedule=prefect.schedules.CronSchedule("0 0 * * *"), ) f.add_edge(p1, t2) f.add_edge(p1, t3) serialized = f.serialize() f2 = prefect.serialization.flow.FlowSchema().load(serialized) assert len(f2.tasks) == 3 assert len(f2.edges) == 2 assert len(f2.reference_tasks()) == 2 assert {t.name for t in f2.reference_tasks()} == {"2", "3"} assert f2.name == f.name assert isinstance(f2.schedule, prefect.schedules.CronSchedule)
def test_serialize_fails_with_no_storage(self): f = Flow(name="test") with pytest.raises(ValueError): s_build = f.serialize(build=True)