Exemplo n.º 1
0
def test_scheme_serialization_basic():
    preload, test_input = map(_stable_json_dump, [
        {'a': 123, 'b': 44, 'c': 92},
        {'a': 42, 'b': 44, 'c': 91},
    ])
    scheme = ZlibPlcdScheme('x_v1', preload)

    scheme_reconstructed = ZlibPlcdScheme.from_json_description_dict(
        scheme.json_description_dict()
    )

    assert len(scheme.compress(test_input)) == 20
    assert scheme_reconstructed.compress(test_input) == scheme.compress(test_input)
Exemplo n.º 2
0
def test_compression_is_better_basic():
    """Checks that PLCD is better than nothing or vanilla
    zlib for a basic input case.
    """
    preload, test_input = map(_stable_json_dump, [
        {'a': 123, 'b': 44, 'c': 92},
        {'a': 42, 'b': 44, 'c': 91},
    ])
    scheme = ZlibPlcdScheme('x_v1', preload)

    assert len(test_input) == 27
    assert len(zlib.compress(test_input)) == 30
    assert len(scheme.compress(test_input)) == 20
Exemplo n.º 3
0
def test_compress_and_decompress():
    """Test that decompress(compress(x)) == x."""
    scheme = ZlibPlcdScheme('hi', 'fandangle')
    for input_str in ('catfood', 'fandangle2'):
        compressed = scheme.compress(input_str)
        assert scheme.decompress(compressed) == input_str