def test_cloudpickle_deserialization_check_raises_on_bad_imports( self, tmpdir): path = str(tmpdir.join("test.prefect")) with open(path, "wb") as f: f.write( b'{"flow": "gASVGAAAAAAAAACMC2Zvb19tYWNoaW5llIwEZnVuY5STlC4=\\n"}' ) with pytest.raises(ImportError, match="foo_machine"): healthchecks.cloudpickle_deserialization_check([path])
def test_cloudpickle_deserialization_check_raises_on_bad_imports(self): bad_bytes = b"\x80\x04\x95\x18\x00\x00\x00\x00\x00\x00\x00\x8c\x0bfoo_machine\x94\x8c\x04func\x94\x93\x94." with tempfile.NamedTemporaryFile() as f: f.write(bad_bytes) f.seek(0) with pytest.raises(ImportError, match="foo_machine"): objs = healthchecks.cloudpickle_deserialization_check( ["{}".format(f.name)])
def test_cloudpickle_deserialization_check_passes_and_returns_objs(self): good_bytes = flow_to_bytes_pickle(Flow("empty")) with tempfile.NamedTemporaryFile() as f: f.write(good_bytes) f.seek(0) objs = healthchecks.cloudpickle_deserialization_check(["{}".format(f.name)]) assert len(objs) == 1 flow = objs.pop() assert isinstance(flow, Flow) assert flow.name == "empty" assert flow.tasks == set()
def test_cloudpickle_deserialization_check_passes_and_returns_multiple_objs(self): flow_one = flow_to_bytes_pickle(Flow("one")) flow_two = flow_to_bytes_pickle(Flow("two")) with tempfile.TemporaryDirectory() as tmpdir: file_one = os.path.join(tmpdir, "one.flow") with open(file_one, "wb") as f: f.write(flow_one) file_two = os.path.join(tmpdir, "two.flow") with open(file_two, "wb") as f: f.write(flow_two) paths = ["{}".format(file_one), "{}".format(file_two)] objs = healthchecks.cloudpickle_deserialization_check(paths) assert len(objs) == 2