"""A segment whose body is gzip with no Content-Encoding header is inflated before the merge; no other body is.""" from __future__ import annotations import gzip import pytest from tests.core.test_rolling_merge_hls_ism import INIT, PARTS, hls_track, make_ctx, no_cancel, server # noqa: F401 from unshackle.core.manifests import HLS @pytest.mark.parametrize( "body, expected", [ pytest.param(gzip.compress, lambda part: part, id="gzip"), pytest.param(lambda part: b"\x1f\x8b\x08" + part, lambda part: b"\x1f\x8b\x08" + part, id="gzip-magic-only"), pytest.param(lambda part: gzip.compress(part)[:-4], lambda part: gzip.compress(part)[:-4], id="cut-gzip"), ], ) def test_only_a_whole_gzip_segment_is_inflated(body, expected, server, tmp_path): # noqa: F811 for i, part in enumerate(PARTS): server.routes[f"/part{i}.m4s"] = body(part) ctx = make_ctx(tmp_path, "out.mp4") HLS.download_track(hls_track(server, False), ctx) assert ctx.save_path.read_bytes() == INIT + b"".join(map(expected, PARTS))