示例#1
0
 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))
示例#2
0
    def test_cloudpickle_deserialization_check_passes_and_returns_objs(self):
        good_bytes = cloudpickle.dumps(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()
示例#3
0
    def test_cloudpickle_deserialization_check_passes_and_returns_multiple_objs(self):
        flow_one = cloudpickle.dumps(Flow("one"))
        flow_two = cloudpickle.dumps(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