"""Release integrity, local loading, metadata exclusions and wheel checks.""" import importlib.util import json from pathlib import Path import shutil import zipfile import numpy as np import pytest from timestral_mlx import TimestralForecaster ROOT=Path(__file__).resolve().parents[1] def test_local_bundle_roundtrip_and_corruption(tmp_path): source=ROOT/'models'/'5M' if not source.exists(): pytest.skip('convert 5M first') for name in ('config.json','model.safetensors','LICENSE','manifest.json'): shutil.copyfile(source/name,tmp_path/name) fc=TimestralForecaster.from_pretrained(tmp_path) assert fc.forecast(np.arange(65,dtype=np.float32),9).quantiles.shape==(1,1,9,21) with (tmp_path/'model.safetensors').open('r+b') as f: f.seek(-1,2); byte=f.read(1); f.seek(-1,2); f.write(bytes([byte[0]^1])) with pytest.raises(ValueError,match='integrity'): TimestralForecaster.from_pretrained(tmp_path) def test_variant_mismatch(): source=ROOT/'models'/'5M' if not source.exists(): pytest.skip('convert 5M first') with pytest.raises(ValueError,match='variant'): TimestralForecaster.from_pretrained(source.parent,variant='not-a-model') def test_apple_metadata_exclusions(): spec=importlib.util.spec_from_file_location('package_release',ROOT/'scripts'/'package_release.py') module=importlib.util.module_from_spec(spec);spec.loader.exec_module(module) for name in ('._README.md','5M/._model.safetensors','__MACOSX/foo','x/.DS_Store','x/a.pyc','x/a.tmp','x/.AppleDouble/README'): assert module.excluded(name),name for name in ('5M/model.safetensors','timestral_mlx/model.py','LICENSE-WEIGHTS'): assert not module.excluded(name),name def test_installable_wheel_inventory(): wheels=[p for p in (ROOT/'dist').glob('*.whl') if not p.name.startswith('._')] if not wheels: pytest.skip('build wheel first') with zipfile.ZipFile(wheels[0]) as z: assert not any(any(p.startswith('._') or p in {'.DS_Store','__MACOSX'} for p in n.split('/')) for n in z.namelist()) for path in (ROOT/'timestral_mlx').glob('*.py'): if not path.name.startswith('._'): assert z.read('timestral_mlx/'+path.name)==path.read_bytes() assert z.read('timestral_mlx-0.1.0.dist-info/licenses/LICENSE-WEIGHTS')==(ROOT/'LICENSE-WEIGHTS').read_bytes()