Coverage for tests/test_hunyuanavatar_sample_inference.py: 100%
23 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-09 04:47 +0000
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-09 04:47 +0000
1#!/usr/bin/env python3
2"""
3Tests for wrapper/hunyuanavatar/sample_inference_audio.py
4"""
6import sys
8from unittest.mock import patch, MagicMock
9from tests.torch_mock import TorchMock
11mock_torch = TorchMock()
13mock_modules = {
14 'nvidia_smi': MagicMock(),
15 'torch': mock_torch,
16 'torchvision': MagicMock(),
17 'torchvision.transforms': MagicMock(),
18 'loguru': MagicMock(),
19 'einops': MagicMock(),
20 'hymm_sp': MagicMock(),
21 'hymm_sp.diffusion': MagicMock(),
22 'hymm_sp.helpers': MagicMock(),
23 'hymm_sp.inference': MagicMock(),
24 'hymm_sp.data_kits': MagicMock(),
25 'hymm_sp.data_kits.audio_preprocessor': MagicMock(),
26}
27mock_modules.update(mock_torch.get_sub_modules())
29sys.path.append("wrapper")
30sys.path.append("wrapper/hunyuanavatar")
32with patch.dict(sys.modules, mock_modules):
33 from hunyuanavatar.sample_inference_audio import align_to
36def test_align_to_already_aligned() -> None:
37 """align_to should return value unchanged when already divisible."""
38 assert align_to(16, 16) == 16
39 assert align_to(32, 8) == 32
40 assert align_to(100, 10) == 100
43def test_align_to_rounds_up() -> None:
44 """align_to rounds up to the next multiple of alignment."""
45 assert align_to(17, 16) == 32
46 assert align_to(1, 16) == 16
47 assert align_to(9, 8) == 16
50def test_align_to_float_input() -> None:
51 """align_to handles float inputs."""
52 assert align_to(16.0, 16) == 16
53 assert align_to(15.5, 8) == 16
56def test_align_to_zero() -> None:
57 """align_to with zero returns zero."""
58 assert align_to(0, 16) == 0