Files
cron-parser-cli/tests/test_cli.py
7000pctAUTO 7ab9b9e010
Some checks failed
CI / test (push) Has been cancelled
Add test files
2026-02-01 15:10:15 +00:00

84 lines
3.1 KiB
Python

"""Tests for CLI interface."""
import pytest
from click.testing import CliRunner
from cronparse.cli import main
class TestCLI:
"""Tests for CLI commands."""
@pytest.fixture
def runner(self):
"""Create CLI runner."""
return CliRunner()
def test_version_option(self, runner):
"""Test --version option."""
result = runner.invoke(main, ["--version"])
assert result.exit_code == 0
assert "cronparse" in result.output.lower()
def test_help_option(self, runner):
"""Test --help option."""
result = runner.invoke(main, ["--help"])
assert result.exit_code == 0
assert "Usage:" in result.output
def test_parse_valid_expression(self, runner):
"""Test parse command with valid expression."""
result = runner.invoke(main, ["parse", "* * * * *"])
assert result.exit_code == 0
assert "Valid" in result.output or "minute" in result.output
def test_parse_invalid_expression(self, runner):
"""Test parse command with invalid expression."""
result = runner.invoke(main, ["parse", "invalid"])
assert result.exit_code != 0
assert "Error" in result.output
def test_next_command(self, runner):
"""Test next command."""
result = runner.invoke(main, ["next", "* * * * *", "--count", "3"])
assert result.exit_code == 0
assert "#1" in result.output or "executions" in result.output.lower()
def test_explain_command(self, runner):
"""Test explain command."""
result = runner.invoke(main, ["explain", "0 9 * * *"])
assert result.exit_code == 0
assert "Description" in result.output or "9" in result.output
def test_from_text_command(self, runner):
"""Test from-text command."""
result = runner.invoke(main, ["from-text", "daily", "at", "9am"])
assert result.exit_code == 0
assert "Cron" in result.output or "cron" in result.output
def test_generate_command_exists(self, runner):
"""Test that generate command exists."""
result = runner.invoke(main, ["generate", "--help"])
assert result.exit_code == 0
def test_invalid_subcommand(self, runner):
"""Test that invalid subcommand shows error."""
result = runner.invoke(main, ["invalid_command"])
assert result.exit_code != 0
assert "No such command" in result.output
def test_parse_json_output(self, runner):
"""Test parse command with JSON output."""
result = runner.invoke(main, ["parse", "* * * * *", "--json"])
assert result.exit_code == 0
assert "minute" in result.output
def test_next_json_output(self, runner):
"""Test next command with JSON output."""
result = runner.invoke(main, ["next", "* * * * *", "--count", "3", "--json"])
assert result.exit_code == 0
def test_next_no_timeline(self, runner):
"""Test next command without timeline."""
result = runner.invoke(main, ["next", "* * * * *", "--count", "3", "--no-timeline"])
assert result.exit_code == 0