import struct import pytest from spriteforge.format import Animation,FLAG_DEPTH, FLAG_NORMALS, Frame, encode_sfa, fnv1a32 from spriteforge.reader import decode_sfa from spriteforge.palette import decode_sfp, encode_sfp def sample(): return Frame(bytes([0,1,1,0,2,2,2,0,0,3,0,0]),4,3,2,3,83,bytes([0,0]*12),bytes([0,1,2,0,4,5,6,0,0,9,0,0]),-1.25,2.5) def test_roundtrip_parallel_streams(): got=decode_sfa(encode_sfa([sample()],animation="idle",directions=(4500,))) assert got.flags==FLAG_NORMALS|FLAG_DEPTH assert got.animation=="idle" and got.directions==(4500,) assert got.frames[0]==sample() and got.layer_orders==((0,),) def test_empty_rows(): f=Frame(bytes([0]*8+[4,0,0,4]),4,3) assert decode_sfa(encode_sfa([f])).frames[0]==f @pytest.mark.parametrize("kind",["magic","size","stream"]) def test_corrupt_rejected(kind): blob=bytearray(encode_sfa([sample()])) if kind=="magic": blob[0]=0 elif kind=="size": struct.pack_into("