From 6ba9c938f6d093112d74c7f1e1abc1243f043fd6 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sun, 22 Mar 2026 18:15:43 +0000 Subject: [PATCH] Initial upload: shell-history-semantic-search v0.1.0 --- tests/test_search.py | 57 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 tests/test_search.py 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