Skip to content

Commit 5715763

Browse files
author
coderfromthenorth93
committed
Add/update tests
1 parent 401d252 commit 5715763

File tree

1 file changed

+192
-1
lines changed

1 file changed

+192
-1
lines changed

tests/comfy_cli/registry/test_config_parser.py

Lines changed: 192 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import pytest
44

5-
from comfy_cli.registry.config_parser import extract_node_configuration
5+
from comfy_cli.registry.config_parser import (
6+
extract_node_configuration,
7+
validate_and_extract_accelerator_classifiers,
8+
validate_and_extract_os_classifiers,
9+
validate_version,
10+
)
611
from comfy_cli.registry.types import (
712
License,
813
Model,
@@ -127,3 +132,189 @@ def test_extract_license_incorrect_format():
127132
assert result is not None, "Expected PyProjectConfig, got None"
128133
assert isinstance(result, PyProjectConfig)
129134
assert result.project.license == License(text="MIT")
135+
136+
def test_extract_node_configuration_with_os_classifiers():
137+
mock_data = {
138+
"project": {
139+
"classifiers": [
140+
"Operating System :: OS Independent",
141+
"Operating System :: Microsoft :: Windows",
142+
"Programming Language :: Python :: 3",
143+
"Topic :: Software Development",
144+
]
145+
}
146+
}
147+
with (
148+
patch("os.path.isfile", return_value=True),
149+
patch("builtins.open", mock_open()),
150+
patch("tomlkit.load", return_value=mock_data),
151+
):
152+
result = extract_node_configuration("fake_path.toml")
153+
154+
assert result is not None
155+
assert len(result.project.supported_os) == 2
156+
assert "OS Independent" in result.project.supported_os
157+
assert "Microsoft :: Windows" in result.project.supported_os
158+
159+
160+
def test_extract_node_configuration_with_accelerator_classifiers():
161+
mock_data = {
162+
"project": {
163+
"classifiers": [
164+
"Environment :: GPU :: NVIDIA CUDA",
165+
"Environment :: GPU :: AMD ROCm",
166+
"Environment :: GPU :: Intel Arc",
167+
"Environment :: NPU :: Huawei Ascend",
168+
"Environment :: GPU :: Apple Metal",
169+
"Programming Language :: Python :: 3",
170+
"Topic :: Software Development",
171+
]
172+
}
173+
}
174+
with (
175+
patch("os.path.isfile", return_value=True),
176+
patch("builtins.open", mock_open()),
177+
patch("tomlkit.load", return_value=mock_data),
178+
):
179+
result = extract_node_configuration("fake_path.toml")
180+
181+
assert result is not None
182+
assert len(result.project.supported_accelerators) == 5
183+
assert "GPU :: NVIDIA CUDA" in result.project.supported_accelerators
184+
assert "GPU :: AMD ROCm" in result.project.supported_accelerators
185+
assert "GPU :: Intel Arc" in result.project.supported_accelerators
186+
assert "NPU :: Huawei Ascend" in result.project.supported_accelerators
187+
assert "GPU :: Apple Metal" in result.project.supported_accelerators
188+
189+
190+
def test_extract_node_configuration_with_comfyui_version():
191+
mock_data = {"project": {"dependencies": ["packge1>=2.0.0", "comfyui-frontend-package>=1.2.3", "package2>=1.0.0"]}}
192+
with (
193+
patch("os.path.isfile", return_value=True),
194+
patch("builtins.open", mock_open()),
195+
patch("tomlkit.load", return_value=mock_data),
196+
):
197+
result = extract_node_configuration("fake_path.toml")
198+
199+
assert result is not None
200+
assert result.project.supported_comfyui_frontend_version == ">=1.2.3"
201+
assert len(result.project.dependencies) == 2
202+
assert "comfyui-frontend-package>=1.2.3" not in result.project.dependencies
203+
assert "packge1>=2.0.0" in result.project.dependencies
204+
assert "package2>=1.0.0" in result.project.dependencies
205+
206+
207+
def test_extract_node_configuration_with_requires_comfyui():
208+
mock_data = {"project": {}, "tool": {"requires-comfyui": "2.0.0"}}
209+
with (
210+
patch("os.path.isfile", return_value=True),
211+
patch("builtins.open", mock_open()),
212+
patch("tomlkit.load", return_value=mock_data),
213+
):
214+
result = extract_node_configuration("fake_path.toml")
215+
216+
assert result is not None
217+
assert result.project.supported_comfyui_version == "2.0.0"
218+
219+
def test_validate_and_extract_os_classifiers_valid():
220+
"""Test OS validation with valid classifiers."""
221+
classifiers = [
222+
"Operating System :: Microsoft :: Windows",
223+
"Operating System :: POSIX :: Linux",
224+
"Operating System :: MacOS",
225+
"Operating System :: OS Independent",
226+
"Programming Language :: Python :: 3",
227+
]
228+
result = validate_and_extract_os_classifiers(classifiers)
229+
expected = ["Microsoft :: Windows", "POSIX :: Linux", "MacOS", "OS Independent"]
230+
assert result == expected
231+
232+
@patch('typer.echo')
233+
def test_validate_and_extract_os_classifiers_invalid(mock_echo):
234+
"""Test OS validation with invalid classifiers."""
235+
classifiers = [
236+
"Operating System :: Microsoft :: Windows",
237+
"Operating System :: Linux", # Invalid - should be "POSIX :: Linux"
238+
"Programming Language :: Python :: 3",
239+
]
240+
result = validate_and_extract_os_classifiers(classifiers)
241+
assert result == []
242+
mock_echo.assert_called_once()
243+
assert "Invalid Operating System classifier found" in mock_echo.call_args[0][0]
244+
245+
246+
def test_validate_and_extract_accelerator_classifiers_valid():
247+
"""Test accelerator validation with valid classifiers."""
248+
classifiers = [
249+
"Environment :: GPU :: NVIDIA CUDA",
250+
"Environment :: GPU :: AMD ROCm",
251+
"Environment :: GPU :: Intel Arc",
252+
"Environment :: NPU :: Huawei Ascend",
253+
"Environment :: GPU :: Apple Metal",
254+
"Programming Language :: Python :: 3",
255+
]
256+
result = validate_and_extract_accelerator_classifiers(classifiers)
257+
expected = ["GPU :: NVIDIA CUDA", "GPU :: AMD ROCm", "GPU :: Intel Arc", "NPU :: Huawei Ascend", "GPU :: Apple Metal"]
258+
assert result == expected
259+
260+
261+
@patch('typer.echo')
262+
def test_validate_and_extract_accelerator_classifiers_invalid(mock_echo):
263+
"""Test accelerator validation with invalid classifiers."""
264+
classifiers = [
265+
"Environment :: GPU :: NVIDIA CUDA",
266+
"Environment :: GPU :: Invalid GPU", # Invalid
267+
"Programming Language :: Python :: 3",
268+
]
269+
result = validate_and_extract_accelerator_classifiers(classifiers)
270+
assert result == []
271+
mock_echo.assert_called_once()
272+
assert "Invalid Environment classifier found" in mock_echo.call_args[0][0]
273+
274+
275+
def test_validate_version_valid():
276+
"""Test version validation with valid versions."""
277+
valid_versions = [
278+
"1.1.1",
279+
">=1.0.0",
280+
"==2.1.0-beta",
281+
"1.5.2",
282+
"~=3.0.0",
283+
"!=1.2.3",
284+
">2.0.0",
285+
"<3.0.0",
286+
"<=4.0.0",
287+
"<>1.0.0",
288+
"=1.0.0",
289+
"1.0.0-alpha1",
290+
">=1.0.0,<2.0.0",
291+
"==1.2.3,!=1.2.4",
292+
">=1.0.0,<=2.0.0,!=1.5.0",
293+
"1.0.0,2.0.0",
294+
">1.0.0,<2.0.0,!=1.5.0-beta",
295+
]
296+
297+
for version in valid_versions:
298+
result = validate_version(version, "test_field")
299+
assert result == version, f"Version {version} should be valid"
300+
301+
302+
@patch('typer.echo')
303+
def test_validate_version_invalid(mock_echo):
304+
"""Test version validation with invalid versions."""
305+
invalid_versions = [
306+
"1.0", # Missing patch version
307+
">=abc", # Invalid version format
308+
"invalid-version", # Completely invalid
309+
"1.0.0.0", # Too many version parts
310+
">>1.0.0", # Invalid operator
311+
">=1.0.0,invalid",
312+
"1.0,2.0.0",
313+
">=1.0.0,>=abc",
314+
]
315+
316+
for version in invalid_versions:
317+
result = validate_version(version, "test_field")
318+
assert result == "", f"Version {version} should be invalid"
319+
320+
assert mock_echo.call_count == len(invalid_versions)

0 commit comments

Comments
 (0)