Skip to content

Commit b03ecaf

Browse files
committed
tests: rename comfyui plugin root folder name
to prevent import name conflict in test scripts Signed-off-by: Huang, Zeyu <11222265+fhfuih@users.noreply.github.com>
1 parent ff46ca8 commit b03ecaf

File tree

14 files changed

+1492
-9
lines changed

14 files changed

+1492
-9
lines changed

apps/ComfyUI-vLLM-Omni/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Top-level package for vllm_omni."""
1+
"""Top-level package for comfyui_vllm_omni."""
22

33
__all__ = [
44
"NODE_CLASS_MAPPINGS",
@@ -10,7 +10,7 @@
1010
__email__ = "11222265+fhfuih@users.noreply.github.com"
1111
__version__ = "0.0.1"
1212

13-
from .vllm_omni.nodes import (
13+
from .comfyui_vllm_omni.nodes import (
1414
VLLMOmniARSampling,
1515
VLLMOmniComprehension,
1616
VLLMOmniDiffusionSampling,
File renamed without changes.
File renamed without changes.

apps/ComfyUI-vLLM-Omni/vllm_omni/utils/api_client.py renamed to apps/ComfyUI-vLLM-Omni/comfyui_vllm_omni/utils/api_client.py

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

apps/ComfyUI-vLLM-Omni/vllm_omni/utils/validators.py renamed to apps/ComfyUI-vLLM-Omni/comfyui_vllm_omni/utils/validators.py

File renamed without changes.

tests/comfyui/conftest.py

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
1+
"""
2+
Conftest for ComfyUI-vLLM-Omni tests.
3+
4+
This module sets up the test environment by:
5+
1. Adding the ComfyUI plugin to Python path
6+
2. Mocking comfy_api.input module (AudioInput, VideoInput) since comfyui is not installed
7+
3. Mocking comfy_extras.nodes_audio module
8+
"""
9+
110
import os
211
import sys
12+
from typing import BinaryIO, TypedDict
13+
from unittest.mock import MagicMock
14+
15+
16+
def pytest_configure(config):
17+
"""
18+
Called after command line options have been parsed and before test collection.
19+
This is the right place to set up sys.path and mock modules.
20+
"""
21+
_setup_comfyui_test_environment()
22+
23+
24+
def _setup_comfyui_test_environment():
25+
"""Set up the test environment for ComfyUI plugin testing."""
26+
# Add ComfyUI plugin path to allow importing comfyui_vllm_omni
27+
_COMFYUI_PLUGIN_PATH = os.path.abspath(
28+
os.path.join(os.path.dirname(__file__), "..", "..", "apps", "ComfyUI-vLLM-Omni")
29+
)
30+
if _COMFYUI_PLUGIN_PATH not in sys.path:
31+
sys.path.insert(0, _COMFYUI_PLUGIN_PATH)
32+
33+
# Now we can import torch (which is safe as it doesn't conflict)
34+
import torch
35+
36+
# === Mock comfy_api.input module ===
37+
class AudioInput(TypedDict):
38+
"""Mock AudioInput TypedDict from comfy_api.input"""
39+
waveform: torch.Tensor # Shape: (B, C, T)
40+
sample_rate: int
41+
42+
class VideoInput:
43+
"""Mock VideoInput class from comfy_api.input"""
44+
def __init__(self, data: bytes = b"mock_video_data"):
45+
self._data = data
46+
47+
def save_to(self, file: str | BinaryIO):
48+
"""Save video data to file or file-like object."""
49+
if isinstance(file, str):
50+
print("Called VideoInput.save_to with file path. Saving to a path is no-op in tests.")
51+
else:
52+
file.write(self._data)
53+
54+
# Create mock comfy_api module hierarchy
55+
mock_comfy_api = MagicMock()
56+
mock_comfy_api_input = MagicMock()
57+
mock_comfy_api_input.AudioInput = AudioInput
58+
mock_comfy_api_input.VideoInput = VideoInput
59+
mock_comfy_api.input = mock_comfy_api_input
60+
61+
# Create mock comfy_extras module
62+
mock_comfy_extras = MagicMock()
63+
mock_nodes_audio = MagicMock()
64+
65+
def mock_load(_: str | BinaryIO):
66+
"""Mock nodes_audio.load that returns a waveform tensor and sample rate."""
67+
# Return mock audio data: (channels, samples) tensor and sample rate
68+
waveform = torch.zeros((1, 24000), dtype=torch.float32)
69+
sample_rate = 24000
70+
return waveform, sample_rate
71+
72+
mock_nodes_audio.load = mock_load
73+
mock_comfy_extras.nodes_audio = mock_nodes_audio
74+
75+
# Install mock modules BEFORE importing any comfyui_vllm_omni code
76+
sys.modules["comfy_api"] = mock_comfy_api
77+
sys.modules["comfy_api.input"] = mock_comfy_api_input
78+
sys.modules["comfy_extras"] = mock_comfy_extras
79+
sys.modules["comfy_extras.nodes_audio"] = mock_nodes_audio
80+
381

4-
# Add the project root directory to Python path
5-
# This allows the tests to import the project
6-
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", "apps", "ComfyUI-vLLM-Omni")))
82+
# Run setup immediately when conftest is imported (before pytest_configure for early loading)
83+
_setup_comfyui_test_environment()

0 commit comments

Comments
 (0)