예제 #1
0
    def test_compress(self):
        zbytes = datablock.compress({
            'pickled':
            True,
            'value':
            pickle.dumps(self.obj, protocol=pickle.HIGHEST_PROTOCOL)
        })
        value = ast.literal_eval(datablock.decompress(zbytes))
        value = datablock.zloads(value.get('value'))
        self.assertEqual(value, self.obj)

        zbytes = datablock.compress({
            'pickled':
            True,
            'value':
            zlib.compress(
                pickle.dumps(self.obj, protocol=pickle.HIGHEST_PROTOCOL), 9)
        })
        value = ast.literal_eval(datablock.decompress(zbytes))
        value = datablock.zloads(value.get('value'))
        self.assertEqual(value, self.obj)

        value = str(self.obj).encode("latin1")
        value = ast.literal_eval(datablock.decompress(value))
        self.assertEqual(value, self.obj)
def test_compress():
    zbytes = datablock.compress({
        "pickled":
        True,
        "value":
        pickle.dumps({"a": {
            "b": "c"
        }}, protocol=pickle.HIGHEST_PROTOCOL),
    })
    value = ast.literal_eval(datablock.decompress(zbytes))
    value = datablock.zloads(value.get("value"))
    assert value == {"a": {"b": "c"}}

    zbytes = datablock.compress({
        "pickled":
        True,
        "value":
        zlib.compress(
            pickle.dumps({"a": {
                "b": "c"
            }}, protocol=pickle.HIGHEST_PROTOCOL), 9),
    })
    value = ast.literal_eval(datablock.decompress(zbytes))
    value = datablock.zloads(value.get("value"))
    assert value == {"a": {"b": "c"}}

    value = str({"a": {"b": "c"}}).encode("latin1")
    value = ast.literal_eval(datablock.decompress(value))
    assert value == {"a": {"b": "c"}}