from slisonner import decoder, encoder
from tests import mocker
from tempfile import mkdtemp
from shutil import rmtree


def test_full_encode_decode_cycle():
    temp_out_dir = mkdtemp()
    slice_id = '2015-01-02 00:00:00'
    x_size, y_size = 10, 16

    temp_slice_path = mocker.generate_slice(x_size, y_size, 'float32')

    slice_meta_encoded, slison_filepath = encoder.encode_slice_file(
        filepath=temp_slice_path,
        slice_duration=300,
        timestamp=slice_id,
        layer_id='london',
        x_size=x_size,
        y_size=y_size,
        value_type='float32',
        out_dir=temp_out_dir)
    slice_data, slice_meta_decoded = decoder.decode_slison(slison_filepath)
    for key, encoded_value in slice_meta_encoded.items():
        assert encoded_value == slice_meta_decoded[key]

    rmtree(temp_out_dir)

[((8, 19, 8, 28), 'tempfile.mkdtemp', 'mkdtemp', ({}, {}), '()', False, 'from tempfile import mkdtemp\n'), ((12, 22, 12, 70), 'tests.mocker.generate_slice', 'mocker.generate_slice', ({(12, 44, 12, 50): 'x_size', (12, 52, 12, 58): 'y_size', (12, 60, 12, 69): '"""float32"""'}, {}), "(x_size, y_size, 'float32')", False, 'from tests import mocker\n'), ((14, 42, 22, 29), 'slisonner.encoder.encode_slice_file', 'encoder.encode_slice_file', (), '', False, 'from slisonner import decoder, encoder\n'), ((23, 37, 23, 75), 'slisonner.decoder.decode_slison', 'decoder.decode_slison', ({(23, 59, 23, 74): 'slison_filepath'}, {}), '(slison_filepath)', False, 'from slisonner import decoder, encoder\n'), ((27, 4, 27, 24), 'shutil.rmtree', 'rmtree', ({(27, 11, 27, 23): 'temp_out_dir'}, {}), '(temp_out_dir)', False, 'from shutil import rmtree\n')]