File size: 3,191 Bytes
369b6f0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
"""Tests for CLI root callback functionality."""
from unittest.mock import patch
from typer.testing import CliRunner
from humigence.cli import app
runner = CliRunner(mix_stderr=False)
def test_root_shows_help():
"""Test that --no-wizard shows help instead of launching wizard."""
result = runner.invoke(app, ["--no-wizard"])
assert result.exit_code == 0
assert "Commands" in result.stdout
def test_root_wizard_with_env_vars(monkeypatch):
"""Test that wizard launches when environment variables are set."""
monkeypatch.setenv("HUMIGENCE_DEFAULT_CMD", "wizard")
monkeypatch.setenv("HUMIGENCE_WIZARD_RUN", "plan")
# Mock the run_wizard function to avoid actual wizard execution
with patch("humigence.cli.run_wizard") as mock_run_wizard:
mock_run_wizard.return_value = 0
result = runner.invoke(app, [])
assert result.exit_code == 0
def test_root_wizard_fallback_to_help():
"""Test that non-TTY environments fall back to help."""
# Mock non-TTY environment
import sys
# Save original values
original_stdin_isatty = sys.stdin.isatty
original_stdout_isatty = sys.stdout.isatty
try:
# Mock non-TTY
sys.stdin.isatty = lambda: False
sys.stdout.isatty = lambda: False
result = runner.invoke(app, [])
assert result.exit_code == 0
assert "Commands" in result.stdout
finally:
# Restore original values
sys.stdin.isatty = original_stdin_isatty
sys.stdout.isatty = original_stdout_isatty
def test_root_wizard_with_train_flag():
"""Test that --train flag is properly handled."""
result = runner.invoke(app, ["--train", "--no-wizard"])
assert result.exit_code == 0
assert "Commands" in result.stdout
def test_root_wizard_with_config_override():
"""Test that --config flag is properly handled."""
result = runner.invoke(app, ["--config", "custom_config.json", "--no-wizard"])
assert result.exit_code == 0
assert "Commands" in result.stdout
def test_root_wizard_with_run_override():
"""Test that --run flag is properly handled."""
result = runner.invoke(app, ["--run", "pipeline", "--no-wizard"])
assert result.exit_code == 0
assert "Commands" in result.stdout
def test_root_wizard_environment_variables(monkeypatch):
"""Test that environment variables are properly respected."""
monkeypatch.setenv("HUMIGENCE_DEFAULT_CMD", "help")
result = runner.invoke(app, [])
assert result.exit_code == 0
assert "Commands" in result.stdout
def test_root_wizard_training_environment_variable(monkeypatch):
"""Test that TRAIN environment variable is properly handled."""
monkeypatch.setenv("TRAIN", "1")
result = runner.invoke(app, ["--no-wizard"])
assert result.exit_code == 0
assert "Commands" in result.stdout
def test_root_wizard_wizard_run_environment_variable(monkeypatch):
"""Test that HUMIGENCE_WIZARD_RUN environment variable is properly handled."""
monkeypatch.setenv("HUMIGENCE_WIZARD_RUN", "validate")
result = runner.invoke(app, ["--no-wizard"])
assert result.exit_code == 0
assert "Commands" in result.stdout
|