Skip to content

Commit f92f329

Browse files
committed
test: add coverage for _print_npm_not_found_help function
Tests cover all three OS-specific branches: - Windows instructions - macOS instructions - Linux instructions (including fallback for unknown OS)
1 parent bc0d87f commit f92f329

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""Tests for install command functionality"""
2+
3+
from io import StringIO
4+
from unittest.mock import patch
5+
6+
import pytest
7+
8+
from comfy_cli.command.install import _print_npm_not_found_help
9+
10+
11+
class TestPrintNpmNotFoundHelp:
12+
"""Tests for _print_npm_not_found_help function"""
13+
14+
@pytest.fixture
15+
def capture_output(self):
16+
"""Fixture to capture rich console output"""
17+
output = StringIO()
18+
with patch("comfy_cli.command.install.rprint", side_effect=lambda *args: output.write(str(args[0]) + "\n" if args else "\n")):
19+
yield output
20+
21+
def test_npm_not_found_help_shows_common_message(self, capture_output):
22+
"""Test that common npm not found message is shown regardless of OS"""
23+
with patch("platform.system", return_value="Linux"):
24+
_print_npm_not_found_help("v20.0.0")
25+
26+
output_text = capture_output.getvalue()
27+
assert "npm is not installed or not found in PATH" in output_text
28+
assert "npm is a package manager that usually comes bundled with Node.js" in output_text
29+
assert "v20.0.0" in output_text
30+
assert "After fixing npm, run your comfy command again" in output_text
31+
32+
def test_npm_not_found_help_windows(self, capture_output):
33+
"""Test Windows-specific instructions"""
34+
with patch("platform.system", return_value="Windows"):
35+
_print_npm_not_found_help("v18.17.0")
36+
37+
output_text = capture_output.getvalue()
38+
assert "How to fix this on Windows" in output_text
39+
assert "Add or remove programs" in output_text
40+
assert "Command Prompt or PowerShell" in output_text
41+
assert "nodejs.org" in output_text
42+
43+
def test_npm_not_found_help_macos(self, capture_output):
44+
"""Test macOS-specific instructions"""
45+
with patch("platform.system", return_value="Darwin"):
46+
_print_npm_not_found_help("v18.17.0")
47+
48+
output_text = capture_output.getvalue()
49+
assert "How to fix this on macOS" in output_text
50+
assert "Homebrew" in output_text
51+
assert "brew install node" in output_text
52+
assert ".pkg file" in output_text
53+
assert "Cmd+Q" in output_text
54+
55+
def test_npm_not_found_help_linux(self, capture_output):
56+
"""Test Linux-specific instructions"""
57+
with patch("platform.system", return_value="Linux"):
58+
_print_npm_not_found_help("v18.17.0")
59+
60+
output_text = capture_output.getvalue()
61+
assert "How to fix this on Linux" in output_text
62+
assert "sudo apt" in output_text
63+
assert "Ubuntu/Debian" in output_text
64+
assert "Fedora" in output_text
65+
assert "NodeSource" in output_text
66+
67+
def test_npm_not_found_help_unknown_os_falls_back_to_linux(self, capture_output):
68+
"""Test that unknown OS falls back to Linux instructions"""
69+
with patch("platform.system", return_value="FreeBSD"):
70+
_print_npm_not_found_help("v18.17.0")
71+
72+
output_text = capture_output.getvalue()
73+
# Should show Linux instructions as fallback
74+
assert "How to fix this on Linux" in output_text

0 commit comments

Comments
 (0)