Initial upload: shell-history-semantic-search v0.1.0
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
This commit is contained in:
71
tests/test_cli.py
Normal file
71
tests/test_cli.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import pytest
|
||||
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
|
||||
Reference in New Issue
Block a user