corridorkey-mrp-mlx/tests/test_weights.py
cmoyates 838bd0dd39
refactor(tests): restructure suite — 15 files to 8, consolidate parity
- Add conftest.py: shared paths, tolerances, skip markers, fixtures
- Consolidate imports/shapes/smoke/forward → test_model_contract.py
- Consolidate all parity (decoder/refiner/backbone/e2e) → test_parity.py
- Fold 2048 slow test into test_engine.py
- Rework test_conversion.py to use public convert_checkpoint() API
- Simplify test_weights.py: drop CLI/env var tests, keep checksum+config
- Rename tiling/compilation test files for consistency
- Delete 10 redundant files

80 tests collected (75 pass, 4 skip, 1 deselected)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 09:58:53 -03:30

84 lines
2.3 KiB
Python

"""Tests for weights download module: config defaults, checksum, hash parsing."""
from __future__ import annotations
import hashlib
from typing import TYPE_CHECKING
from corridorkey_mlx.weights import (
DEFAULT_ASSET_NAME,
DEFAULT_GITHUB_OWNER,
DEFAULT_GITHUB_REPO,
_parse_hash_line,
cache_dir,
default_asset_name,
default_tag,
github_owner_repo,
verify_sha256,
)
if TYPE_CHECKING:
from pathlib import Path
# -- Config defaults ---------------------------------------------------------
class TestConfig:
def test_default_owner_repo(self) -> None:
owner, repo = github_owner_repo()
assert owner == DEFAULT_GITHUB_OWNER
assert repo == DEFAULT_GITHUB_REPO
def test_default_asset_name(self) -> None:
assert default_asset_name() == DEFAULT_ASSET_NAME
def test_default_tag(self) -> None:
assert default_tag() == "latest"
# -- Cache directory ---------------------------------------------------------
class TestCacheDir:
def test_contains_tag(self) -> None:
p = cache_dir("v1.0.0")
assert p.parts[-1] == "v1.0.0"
assert p.parts[-2] == "weights"
def test_latest_tag(self) -> None:
p = cache_dir("latest")
assert p.parts[-1] == "latest"
# -- Checksum ----------------------------------------------------------------
class TestChecksum:
def test_parse_hash_only(self) -> None:
h = "a" * 64
assert _parse_hash_line(h, "file.bin") == h
def test_parse_hash_with_filename(self) -> None:
h = "b" * 64
assert _parse_hash_line(f"{h} file.bin", "file.bin") == h
def test_parse_hash_uppercase(self) -> None:
h = "C" * 64
assert _parse_hash_line(h, "file.bin") == h.lower()
def test_parse_hash_garbage(self) -> None:
assert _parse_hash_line("not a hash", "file.bin") is None
def test_verify_sha256_valid(self, tmp_path: Path) -> None:
content = b"hello world"
expected = hashlib.sha256(content).hexdigest()
p = tmp_path / "test.bin"
p.write_bytes(content)
assert verify_sha256(p, expected) is True
def test_verify_sha256_invalid(self, tmp_path: Path) -> None:
p = tmp_path / "test.bin"
p.write_bytes(b"hello world")
assert verify_sha256(p, "0" * 64) is False