57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
import numpy as np
|
|
import sqlite3
|
|
|
|
from shell_history_search.core import SearchEngine, SearchResult, IndexingService
|
|
from shell_history_search.db import init_database
|
|
|
|
|
|
class TestSearchEngine:
|
|
def test_init_with_db_path(self, temp_db_path):
|
|
conn = init_database(temp_db_path)
|
|
engine = SearchEngine(db_path=conn)
|
|
stats = engine.get_stats()
|
|
|
|
assert stats["total_commands"] == 0
|
|
assert stats["total_embeddings"] == 0
|
|
conn.close()
|
|
|
|
def test_get_stats_empty(self, temp_db_path):
|
|
conn = init_database(temp_db_path)
|
|
engine = SearchEngine(db_path=conn)
|
|
stats = engine.get_stats()
|
|
|
|
assert stats["total_commands"] == 0
|
|
assert stats["total_embeddings"] == 0
|
|
assert stats["shell_counts"] == {}
|
|
assert stats["embedding_model"] == "all-MiniLM-L6-v2"
|
|
assert stats["embedding_dim"] == 384
|
|
conn.close()
|
|
|
|
def test_clear_all(self, temp_db_path):
|
|
conn = init_database(temp_db_path)
|
|
engine = SearchEngine(db_path=conn)
|
|
engine.clear_all()
|
|
|
|
stats = engine.get_stats()
|
|
assert stats["total_commands"] == 0
|
|
assert stats["total_embeddings"] == 0
|
|
conn.close()
|
|
|
|
|
|
class TestSearchResult:
|
|
def test_search_result_creation(self):
|
|
result = SearchResult(
|
|
command="git commit",
|
|
shell_type="bash",
|
|
timestamp=1700000000,
|
|
similarity=0.95,
|
|
command_id=1,
|
|
)
|
|
|
|
assert result.command == "git commit"
|
|
assert result.shell_type == "bash"
|
|
assert result.timestamp == 1700000000
|
|
assert result.similarity == 0.95
|
|
assert result.command_id == 1 |