Add exporters, utils, and tests
This commit is contained in:
112
.tests/test_cli.py
Normal file
112
.tests/test_cli.py
Normal file
@@ -0,0 +1,112 @@
|
||||
"""Tests for CLI module."""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from click.testing import CliRunner
|
||||
import pytest
|
||||
|
||||
from termflow.__main__ import cli
|
||||
|
||||
|
||||
class TestCLI:
|
||||
"""Test CLI commands."""
|
||||
|
||||
@pytest.fixture
|
||||
def runner(self):
|
||||
"""Create CLI runner."""
|
||||
return CliRunner()
|
||||
|
||||
@pytest.fixture
|
||||
def temp_db(self, tmp_path):
|
||||
"""Create temporary database."""
|
||||
db_path = tmp_path / "test.db"
|
||||
return db_path
|
||||
|
||||
def test_version(self, runner):
|
||||
"""Test version command."""
|
||||
result = runner.invoke(cli, ["--version"])
|
||||
assert result.exit_code == 0
|
||||
assert "0.1.0" in result.output
|
||||
|
||||
def test_help(self, runner):
|
||||
"""Test help command."""
|
||||
result = runner.invoke(cli, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "record" in result.output
|
||||
assert "visualize" in result.output
|
||||
assert "compare" in result.output
|
||||
assert "export" in result.output
|
||||
|
||||
def test_list_sessions_empty(self, runner, temp_db):
|
||||
"""Test listing sessions when none exist."""
|
||||
result = runner.invoke(cli, ["--db", str(temp_db), "list"])
|
||||
assert result.exit_code == 0
|
||||
assert "No sessions" in result.output or "recorded" in result.output
|
||||
|
||||
def test_list_sessions_with_data(self, runner, temp_db):
|
||||
"""Test listing sessions with existing data."""
|
||||
from termflow.core.database import SessionDatabase
|
||||
from termflow.core.session import Session
|
||||
|
||||
db = SessionDatabase(temp_db)
|
||||
session = Session(name="test-session")
|
||||
db.create_session(session)
|
||||
|
||||
result = runner.invoke(cli, ["--db", str(temp_db), "list"])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "test-session" in result.output
|
||||
|
||||
def test_show_session_not_found(self, runner, temp_db):
|
||||
"""Test showing non-existent session."""
|
||||
result = runner.invoke(cli, ["--db", str(temp_db), "show", "999"])
|
||||
assert result.exit_code == 0
|
||||
assert "not found" in result.output
|
||||
|
||||
def test_record_help(self, runner):
|
||||
"""Test record command help."""
|
||||
result = runner.invoke(cli, ["record", "--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "--interactive" in result.output
|
||||
assert "--from-history" in result.output
|
||||
|
||||
def test_visualize_help(self, runner):
|
||||
"""Test visualize command help."""
|
||||
result = runner.invoke(cli, ["visualize", "--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "--style" in result.output
|
||||
assert "--format" in result.output
|
||||
|
||||
def test_compare_help(self, runner):
|
||||
"""Test compare command help."""
|
||||
result = runner.invoke(cli, ["compare", "--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "--sessions" in result.output
|
||||
assert "--all" in result.output
|
||||
|
||||
def test_export_help(self, runner):
|
||||
"""Test export command help."""
|
||||
result = runner.invoke(cli, ["export", "--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "--format" in result.output
|
||||
assert "--output" in result.output
|
||||
|
||||
def test_visualize_session_requires_db(self, runner, temp_db):
|
||||
"""Test visualizing session without any sessions."""
|
||||
result = runner.invoke(cli, ["--db", str(temp_db), "visualize", "session"])
|
||||
assert result.exit_code == 0
|
||||
assert "No sessions" in result.output or "not found" in result.output
|
||||
|
||||
def test_visualize_git_not_repo(self, runner, tmp_path):
|
||||
"""Test visualizing git in non-git directory."""
|
||||
result = runner.invoke(
|
||||
cli,
|
||||
["--db", str(tmp_path / "test.db"), "visualize", "git"],
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "Not a git repository" in result.output or result.exit_code == 0
|
||||
|
||||
def test_export_requires_output(self, runner):
|
||||
"""Test that export requires output file."""
|
||||
result = runner.invoke(cli, ["export", "session"])
|
||||
assert result.exit_code != 0
|
||||
Reference in New Issue
Block a user