diff --git a/tests/test_search.py b/tests/test_search.py new file mode 100644 index 0000000..6438284 --- /dev/null +++ b/tests/test_search.py @@ -0,0 +1,57 @@ +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 \ No newline at end of file