"""Asset-reader regression tests; standard library only, no model weights.""" import importlib.util import json from pathlib import Path import struct import tempfile from types import SimpleNamespace import unittest import zipfile MODULE_PATH = Path(__file__).resolve().parents[2] / 'tools/community_models/prepare_kitten_tts2_gguf.py' SPEC = importlib.util.spec_from_file_location('kitten_prepare', MODULE_PATH) PREPARE = importlib.util.module_from_spec(SPEC) SPEC.loader.exec_module(PREPARE) class VoiceArrayTests(unittest.TestCase): def read(self, descriptor, shape, payload, dtype, version=1): header = repr({'descr': descriptor, 'fortran_order': False, 'shape': shape}).encode('ascii') width = 2 if version == 1 else 4 data = b'\x93NUMPY' + bytes([version, 0]) + len(header).to_bytes(width, 'little') + header + payload with tempfile.TemporaryDirectory() as directory: path = Path(directory) / 'voice.npz' with zipfile.ZipFile(path, 'w') as archive: archive.writestr('value.npy', data) return PREPARE.read_voice_array(path, 'value', dtype) def test_upstream_numeric_types_and_endianness(self): for version in (1, 2, 3): self.assertEqual(self.read('i4', (2,), struct.pack('>2i', 4299, 6560), 'i4', version), [4299, 6560]) def test_rejects_object_or_wrong_shape(self): for descriptor, shape in (('|O', (1,)), ('