49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Tests for session recorder."""
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
import pytest
|
|
|
|
from termflow.core.recorder import SessionRecorder, InteractiveRecorder
|
|
from termflow.core.session import Session, Command
|
|
|
|
|
|
class TestSessionRecorder:
|
|
"""Test session recorder."""
|
|
|
|
def test_record_from_history(self, tmp_path):
|
|
"""Test recording from shell history."""
|
|
db_path = str(tmp_path / "test.db")
|
|
recorder = SessionRecorder(db_path)
|
|
|
|
session = recorder.record_from_history("test-session", count=10)
|
|
|
|
assert session.name == "test-session"
|
|
assert isinstance(session, Session)
|
|
|
|
def test_save_to_database(self, tmp_path):
|
|
"""Test saving session to database."""
|
|
from termflow.core.database import SessionDatabase
|
|
|
|
db_path = str(tmp_path / "test.db")
|
|
recorder = SessionRecorder(db_path)
|
|
|
|
session = Session(name="test-save")
|
|
session.add_command(Command(command="ls"))
|
|
recorder._current_session = session
|
|
|
|
saved = recorder.save_to_database()
|
|
|
|
assert saved.id is not None
|
|
assert saved.name == "test-save"
|
|
|
|
|
|
class TestInteractiveRecorder:
|
|
"""Test interactive recorder."""
|
|
|
|
def test_init(self, tmp_path):
|
|
"""Test interactive recorder initialization."""
|
|
db_path = str(tmp_path / "test.db")
|
|
recorder = InteractiveRecorder(db_path)
|
|
assert recorder.db_path == db_path
|