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, 'tempfile.mkdtemp', 'mkdtemp', False, 'from tempfile import mkdtemp\n'), (12, 'tests.mocker.generate_slice', 'mocker.generate_slice', False, 'from tests import mocker\n'), (14, 'slisonner.encoder.encode_slice_file', 'encoder.encode_slice_file', False, 'from slisonner import decoder, encoder\n'), (23, 'slisonner.decoder.decode_slison', 'decoder.decode_slison', False, 'from slisonner import decoder, encoder\n'), (27, 'shutil.rmtree', 'rmtree', False, 'from shutil import rmtree\n')]