"""Smoke tests. Torch-backed checks skip when torch is not installed.""" from __future__ import annotations import importlib.util import json import os import pytest ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) HAS_TORCH = importlib.util.find_spec("torch") is not None def test_tts_json_structure_and_compressed_channels(): path = os.path.join(ROOT, "tts.json") with open(path, encoding="utf-8") as f: data = json.load(f) ttl = data["ttl"] assert ttl["latent_dim"] == 24 assert ttl["chunk_compress_factor"] == 6 assert ttl["latent_dim"] * ttl["chunk_compress_factor"] == 144 @pytest.mark.skipif(not HAS_TORCH, reason="torch not installed") def test_compress_decompress_roundtrip(): import torch from models.utils import compress_latents, decompress_latents z = torch.randn(1, 24, 12) f = 6 c = compress_latents(z, factor=f) assert c.shape[1] == 24 * f back = decompress_latents(c, factor=f, target_channels=24) assert back.shape == z.shape @pytest.mark.skipif(not HAS_TORCH, reason="torch not installed") def test_load_ttl_config_matches_repo(): from models.utils import load_ttl_config cfg = load_ttl_config(os.path.join(ROOT, "tts.json")) assert cfg["chunk_compress_factor"] == 6 assert cfg["latent_dim"] == 24 assert cfg["compressed_channels"] == 24 * 6 @pytest.mark.skipif(not HAS_TORCH, reason="torch not installed") def test_dp_network_latent_channels_forwarded(): from models.dp_network import DPNetwork net = DPNetwork(vocab_size=100, latent_channels=128) assert net.ref_encoder.input_proj.in_channels == 128