Coverage for tests/test_wrapper_hunyuanimage.py: 100%
54 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
3import sys
4import pytest
6from unittest.mock import patch
7from unittest.mock import MagicMock
8from tests.torch_mock import TorchMock
9from tests.diffusers_mock import DiffusersMock
11mock_torch = TorchMock()
12mock_diffusers = DiffusersMock()
14sys.path.append("hunyuanimage")
16mock_modules = {
17 "torch": mock_torch,
18 "diffusers": mock_diffusers,
19 "transformers": MagicMock(),
20 "xfuser": MagicMock(),
21 "xfuser.config": MagicMock(),
22}
23mock_modules.update(mock_torch.get_sub_modules())
24mock_modules.update(mock_diffusers.get_sub_modules())
26with patch.dict(sys.modules, mock_modules):
27 from hunyuanimage.wrapper_hunyuanimage import HunyuanImageGeneration
30@pytest.mark.asyncio
31async def test_wrapper_hunyuanimage() -> None:
32 model = HunyuanImageGeneration()
33 assert model is not None
34 assert model.model_name == "hunyuanimage"
35 assert model.status == "initializing"
37 with pytest.raises(ValueError, match="Model not initialized. Current status: initializing."):
38 await model.generate(64, 48, "test prompt")
40 model.status = "ok"
41 with pytest.raises(ValueError, match="HunyuanImage model not loaded."):
42 await model.generate(64, 48, "test prompt")
43 model.status == "initializing"
45 model.init()
46 assert model.status == "ok"
48 # Mock model init()
49 model.model.vae.config.ffactor_spatial = 8
51 health = model.get_health()
52 assert health is not None
54 with pytest.raises(ValueError, match="Missing JSON body"):
55 await model.get_rest_args(None)
56 with pytest.raises(ValueError, match="Missing 'prompt' parameter"):
57 await model.get_rest_args({})
59 rest_args = await model.get_rest_args({
60 "prompt": "test prompt",
61 })
62 assert rest_args == {
63 "task": "hunyuanimage",
64 "args": {
65 "width": 640,
66 "height": 480,
67 "prompt": "test prompt",
68 "sampling_steps": 25,
69 "seed": None,
70 }
71 }
73 await model.warmup()
75 image = await model.generate(
76 width=1024,
77 height=1024,
78 prompt="Test prompt")
79 assert image is not None
81 with pytest.raises(ValueError, match="2048x1024 too large. Max is 1024 x 1024."):
82 await model.generate(width=2048, height=1024, prompt="Prompt")
84 with pytest.raises(ValueError, match="Width 1027 not supported. Must be multiple of 8."):
85 await model.generate(width=1027, height=512, prompt="Prompt")
87 with pytest.raises(ValueError, match="Height 513 not supported. Must be multiple of 8."):
88 await model.generate(width=512, height=513, prompt="Prompt")
91@pytest.mark.asyncio
92async def test_wrapper_hunyuanimage_parallel() -> None:
93 model = HunyuanImageGeneration()
94 model.init()
95 assert model.status == "ok"
96 model.rank = 1 # Simulate distributed rank
97 image = await model.generate(
98 width=128,
99 height=128,
100 prompt="Test prompt")
101 assert image is None # Only rank 0 generates images