|
| 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( |
| 19 | + "comfy_cli.command.install.rprint", |
| 20 | + side_effect=lambda *args: output.write(str(args[0]) + "\n" if args else "\n"), |
| 21 | + ): |
| 22 | + yield output |
| 23 | + |
| 24 | + def test_npm_not_found_help_shows_common_message(self, capture_output): |
| 25 | + """Test that common npm not found message is shown regardless of OS""" |
| 26 | + with patch("platform.system", return_value="Linux"): |
| 27 | + _print_npm_not_found_help("v20.0.0") |
| 28 | + |
| 29 | + output_text = capture_output.getvalue() |
| 30 | + assert "npm is not installed or not found in PATH" in output_text |
| 31 | + assert "npm is a package manager that usually comes bundled with Node.js" in output_text |
| 32 | + assert "v20.0.0" in output_text |
| 33 | + assert "After fixing npm, run your comfy command again" in output_text |
| 34 | + |
| 35 | + def test_npm_not_found_help_windows(self, capture_output): |
| 36 | + """Test Windows-specific instructions""" |
| 37 | + with patch("platform.system", return_value="Windows"): |
| 38 | + _print_npm_not_found_help("v18.17.0") |
| 39 | + |
| 40 | + output_text = capture_output.getvalue() |
| 41 | + assert "How to fix this on Windows" in output_text |
| 42 | + assert "Add or remove programs" in output_text |
| 43 | + assert "Command Prompt or PowerShell" in output_text |
| 44 | + |
| 45 | + def test_npm_not_found_help_macos(self, capture_output): |
| 46 | + """Test macOS-specific instructions""" |
| 47 | + with patch("platform.system", return_value="Darwin"): |
| 48 | + _print_npm_not_found_help("v18.17.0") |
| 49 | + |
| 50 | + output_text = capture_output.getvalue() |
| 51 | + assert "How to fix this on macOS" in output_text |
| 52 | + assert "Homebrew" in output_text |
| 53 | + assert "brew install node" in output_text |
| 54 | + assert ".pkg file" in output_text |
| 55 | + assert "Cmd+Q" in output_text |
| 56 | + |
| 57 | + def test_npm_not_found_help_linux(self, capture_output): |
| 58 | + """Test Linux-specific instructions""" |
| 59 | + with patch("platform.system", return_value="Linux"): |
| 60 | + _print_npm_not_found_help("v18.17.0") |
| 61 | + |
| 62 | + output_text = capture_output.getvalue() |
| 63 | + assert "How to fix this on Linux" in output_text |
| 64 | + assert "sudo apt" in output_text |
| 65 | + assert "Ubuntu/Debian" in output_text |
| 66 | + assert "Fedora" in output_text |
| 67 | + assert "NodeSource" in output_text |
| 68 | + |
| 69 | + def test_npm_not_found_help_unknown_os_falls_back_to_linux(self, capture_output): |
| 70 | + """Test that unknown OS falls back to Linux instructions""" |
| 71 | + with patch("platform.system", return_value="FreeBSD"): |
| 72 | + _print_npm_not_found_help("v18.17.0") |
| 73 | + |
| 74 | + output_text = capture_output.getvalue() |
| 75 | + # Should show Linux instructions as fallback |
| 76 | + assert "How to fix this on Linux" in output_text |
0 commit comments