|
| 1 | +import re |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +from typer.testing import CliRunner |
| 5 | + |
| 6 | +from comfy_cli.command.custom_nodes.command import app |
| 7 | + |
| 8 | +runner = CliRunner(mix_stderr=False) |
| 9 | + |
| 10 | + |
| 11 | +def strip_ansi(text): |
| 12 | + """Remove ANSI escape sequences from text.""" |
| 13 | + ansi_escape = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])") |
| 14 | + return ansi_escape.sub("", text) |
| 15 | + |
| 16 | + |
| 17 | +def test_install_no_deps_option_exists(): |
| 18 | + """Test that the --no-deps option appears in the help.""" |
| 19 | + result = runner.invoke(app, ["install", "--help"]) |
| 20 | + assert result.exit_code == 0 |
| 21 | + clean_output = strip_ansi(result.stdout) |
| 22 | + assert "--no-deps" in clean_output |
| 23 | + assert "Skip dependency installation" in clean_output |
| 24 | + |
| 25 | + |
| 26 | +def test_install_fast_deps_and_no_deps_mutually_exclusive(): |
| 27 | + """Test that --fast-deps and --no-deps cannot be used together.""" |
| 28 | + result = runner.invoke(app, ["install", "test-node", "--fast-deps", "--no-deps"]) |
| 29 | + assert result.exit_code != 0 |
| 30 | + # Check both stdout and stderr for the error message |
| 31 | + output = result.stdout + result.stderr |
| 32 | + assert "Cannot use --fast-deps and --no-deps together" in output |
| 33 | + |
| 34 | + |
| 35 | +def test_install_no_deps_alone_works(): |
| 36 | + """Test that --no-deps can be used by itself.""" |
| 37 | + with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute: |
| 38 | + result = runner.invoke(app, ["install", "test-node", "--no-deps"]) |
| 39 | + |
| 40 | + # Should not exit with error due to mutual exclusivity |
| 41 | + if result.exit_code != 0: |
| 42 | + # Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity |
| 43 | + assert "Cannot use --fast-deps and --no-deps together" not in result.stdout |
| 44 | + |
| 45 | + # Verify execute_cm_cli was called with no_deps=True |
| 46 | + if mock_execute.called: |
| 47 | + _, kwargs = mock_execute.call_args |
| 48 | + assert kwargs.get("no_deps") is True |
| 49 | + assert kwargs.get("fast_deps") is False |
| 50 | + |
| 51 | + |
| 52 | +def test_install_fast_deps_alone_works(): |
| 53 | + """Test that --fast-deps can be used by itself.""" |
| 54 | + with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute: |
| 55 | + result = runner.invoke(app, ["install", "test-node", "--fast-deps"]) |
| 56 | + |
| 57 | + # Should not exit with error due to mutual exclusivity |
| 58 | + if result.exit_code != 0: |
| 59 | + # Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity |
| 60 | + assert "Cannot use --fast-deps and --no-deps together" not in result.stdout |
| 61 | + |
| 62 | + # Verify execute_cm_cli was called with fast_deps=True |
| 63 | + if mock_execute.called: |
| 64 | + _, kwargs = mock_execute.call_args |
| 65 | + assert kwargs.get("fast_deps") is True |
| 66 | + assert kwargs.get("no_deps") is False |
| 67 | + |
| 68 | + |
| 69 | +def test_install_neither_deps_option(): |
| 70 | + """Test that install works without any deps options.""" |
| 71 | + with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute: |
| 72 | + result = runner.invoke(app, ["install", "test-node"]) |
| 73 | + |
| 74 | + # Should not exit with error due to mutual exclusivity |
| 75 | + if result.exit_code != 0: |
| 76 | + # Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity |
| 77 | + assert "Cannot use --fast-deps and --no-deps together" not in result.stdout |
| 78 | + |
| 79 | + # Verify execute_cm_cli was called with both flags False |
| 80 | + if mock_execute.called: |
| 81 | + _, kwargs = mock_execute.call_args |
| 82 | + assert kwargs.get("fast_deps") is False |
| 83 | + assert kwargs.get("no_deps") is False |
| 84 | + |
| 85 | + |
| 86 | +def test_multiple_commands_work_independently(): |
| 87 | + """Test that multiple commands work independently without state interference.""" |
| 88 | + # First command with --no-deps should work |
| 89 | + with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli"): |
| 90 | + result1 = runner.invoke(app, ["install", "test-node", "--no-deps"]) |
| 91 | + if result1.exit_code != 0: |
| 92 | + assert "Cannot use --fast-deps and --no-deps together" not in result1.stdout |
| 93 | + |
| 94 | + # Second command with --fast-deps should also work |
| 95 | + with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli"): |
| 96 | + result2 = runner.invoke(app, ["install", "test-node2", "--fast-deps"]) |
| 97 | + if result2.exit_code != 0: |
| 98 | + assert "Cannot use --fast-deps and --no-deps together" not in result2.stdout |
0 commit comments