Files
shell-history-semantic-search/tests/test_cli.py

71 lines
2.3 KiB
Python

from click.testing import CliRunner
from shell_history_search.cli import cli
class TestCLI:
def test_cli_help(self):
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
assert "Usage:" in result.output
assert "--help" in result.output
def test_index_command(self):
runner = CliRunner()
result = runner.invoke(cli, ["index"])
assert result.exit_code == 0
assert "Indexing" in result.output or "Indexed" in result.output
def test_stats_command(self):
runner = CliRunner()
result = runner.invoke(cli, ["stats"])
assert result.exit_code == 0
assert "Statistics" in result.output or "total" in result.output.lower()
def test_search_command(self):
runner = CliRunner()
result = runner.invoke(cli, ["search", "git commit"])
assert result.exit_code == 0
def test_search_with_limit(self):
runner = CliRunner()
result = runner.invoke(cli, ["search", "git", "--limit", "5"])
assert result.exit_code == 0
def test_search_with_shell_filter(self):
runner = CliRunner()
result = runner.invoke(cli, ["search", "git", "--shell", "bash"])
assert result.exit_code == 0
def test_search_with_json_output(self):
runner = CliRunner()
result = runner.invoke(cli, ["search", "git", "--json"])
assert result.exit_code == 0
import json
try:
data = json.loads(result.output)
assert isinstance(data, list)
except json.JSONDecodeError:
pass
def test_index_with_shell_filter(self):
runner = CliRunner()
result = runner.invoke(cli, ["index", "--shell", "bash"])
assert result.exit_code == 0
def test_index_with_invalid_shell(self):
runner = CliRunner()
result = runner.invoke(cli, ["index", "--shell", "csh"])
assert result.exit_code != 0
def test_clear_command_no_confirm(self):
runner = CliRunner()
result = runner.invoke(cli, ["clear"], input="n\n")
assert result.exit_code != 0
def test_verbose_flag(self):
runner = CliRunner()
result = runner.invoke(cli, ["-v", "stats"])
assert result.exit_code == 0