Python · 880 bytes Raw Blame History
1 """Private GGUF IO helper coverage."""
2
3 from __future__ import annotations
4
5 import io
6 import struct
7
8 import pytest
9
10 from dlm.export._gguf_io import _TYPE_ARRAY, _TYPE_STRING, _read_string, _read_u64, _skip_value
11
12
13 def test_read_u64_short_read_raises() -> None:
14 with pytest.raises(struct.error, match="short read"):
15 _read_u64(io.BytesIO(b"\x01\x02"))
16
17
18 def test_read_string_short_read_raises() -> None:
19 data = io.BytesIO(struct.pack("<Q", 4) + b"ab")
20
21 with pytest.raises(struct.error, match="short read in string"):
22 _read_string(data)
23
24
25 def test_skip_value_string_array_huge_length_raises() -> None:
26 data = io.BytesIO(
27 struct.pack("<I", _TYPE_STRING)
28 + struct.pack("<Q", 1)
29 + struct.pack("<Q", (16 * 1024 * 1024) + 1)
30 )
31
32 with pytest.raises(struct.error, match="exceeds bound"):
33 _skip_value(data, _TYPE_ARRAY)