Skip to content

Commit aafd539

Browse files
committed
LCORE-1527: Don't ignore types in test_vector_search.py
1 parent 84a81d1 commit aafd539

1 file changed

Lines changed: 26 additions & 25 deletions

File tree

tests/unit/utils/test_vector_search.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
class TestIsSolrEnabled:
2727
"""Tests for _is_solr_enabled function."""
2828

29-
def test_solr_enabled_true(self, mocker) -> None: # type: ignore[no-untyped-def]
29+
def test_solr_enabled_true(self, mocker: MockerFixture) -> None:
3030
"""Test when Solr is enabled in configuration."""
3131
config_mock = mocker.Mock(spec=AppConfig)
3232
config_mock.inline_solr_enabled = True
3333
mocker.patch("utils.vector_search.configuration", config_mock)
3434
assert _is_solr_enabled() is True
3535

36-
def test_solr_enabled_false(self, mocker) -> None: # type: ignore[no-untyped-def]
36+
def test_solr_enabled_false(self, mocker: MockerFixture) -> None:
3737
"""Test when Solr is disabled in configuration."""
3838
config_mock = mocker.Mock(spec=AppConfig)
3939
config_mock.inline_solr_enabled = False
@@ -78,7 +78,7 @@ def test_with_solr_filters(self) -> None:
7878
class TestExtractByokRagChunks:
7979
"""Tests for _extract_byok_rag_chunks function."""
8080

81-
def test_extract_chunks_with_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
81+
def test_extract_chunks_with_metadata(self, mocker: MockerFixture) -> None:
8282
"""Test extraction of chunks with metadata."""
8383
# Create mock chunks
8484
chunk1 = mocker.Mock()
@@ -107,7 +107,7 @@ def test_extract_chunks_with_metadata(self, mocker) -> None: # type: ignore[no-
107107
assert result[0]["source"] == "test_store"
108108
assert result[0]["doc_id"] == "doc_1"
109109

110-
def test_extract_chunks_without_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
110+
def test_extract_chunks_without_metadata(self, mocker: MockerFixture) -> None:
111111
"""Test extraction of chunks without metadata."""
112112
chunk = mocker.Mock()
113113
chunk.content = "Test content"
@@ -190,7 +190,7 @@ def test_format_chunk_with_attributes(self) -> None:
190190
class TestExtractSolrDocumentMetadata:
191191
"""Tests for _extract_solr_document_metadata function."""
192192

193-
def test_extract_from_dict_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
193+
def test_extract_from_dict_metadata(self, mocker: MockerFixture) -> None:
194194
"""Test extraction from dict-based metadata."""
195195
chunk = mocker.Mock()
196196
chunk.metadata = {
@@ -205,9 +205,7 @@ def test_extract_from_dict_metadata(self, mocker) -> None: # type: ignore[no-un
205205
assert title == "Test Document"
206206
assert reference_url == "https://example.com/doc"
207207

208-
def test_extract_from_chunk_metadata_object( # type: ignore[no-untyped-def]
209-
self, mocker
210-
) -> None:
208+
def test_extract_from_chunk_metadata_object(self, mocker: MockerFixture) -> None:
211209
"""Test extraction from typed chunk_metadata object."""
212210
chunk_meta = mocker.Mock()
213211
chunk_meta.doc_id = "doc_456"
@@ -224,7 +222,7 @@ def test_extract_from_chunk_metadata_object( # type: ignore[no-untyped-def]
224222
assert title == "Another Document"
225223
assert reference_url == "https://example.com/another"
226224

227-
def test_extract_with_missing_fields(self, mocker) -> None: # type: ignore[no-untyped-def]
225+
def test_extract_with_missing_fields(self, mocker: MockerFixture) -> None:
228226
"""Test extraction when some fields are missing."""
229227
chunk = mocker.Mock()
230228
chunk.metadata = {"doc_id": "doc_789"}
@@ -261,7 +259,7 @@ def test_returns_default_when_rhokp_url_unset(self, mocker: MockerFixture) -> No
261259
class TestBuildDocumentUrl:
262260
"""Tests for _build_document_url function."""
263261

264-
def test_offline_mode_with_doc_id(self, mocker) -> None: # type: ignore[no-untyped-def]
262+
def test_offline_mode_with_doc_id(self, mocker: MockerFixture) -> None:
265263
"""Test URL building in offline mode with doc_id."""
266264
config_mock = mocker.Mock()
267265
config_mock.okp.rhokp_url = "https://mimir.test"
@@ -283,7 +281,7 @@ def test_online_mode_with_reference_url(self) -> None:
283281
assert doc_url == "https://docs.example.com/page"
284282
assert reference_doc == "https://docs.example.com/page"
285283

286-
def test_online_mode_without_http(self, mocker) -> None: # type: ignore[no-untyped-def]
284+
def test_online_mode_without_http(self, mocker: MockerFixture) -> None:
287285
"""Test online mode when reference_url doesn't start with http."""
288286
config_mock = mocker.Mock()
289287
config_mock.okp.rhokp_url = "https://mimir.test"
@@ -307,7 +305,7 @@ def test_offline_mode_without_doc_id(self) -> None:
307305
class TestConvertSolrChunksToRagFormat:
308306
"""Tests for _convert_solr_chunks_to_rag_format function."""
309307

310-
def test_convert_with_metadata_offline(self, mocker) -> None: # type: ignore[no-untyped-def]
308+
def test_convert_with_metadata_offline(self, mocker: MockerFixture) -> None:
311309
"""Test conversion with metadata in offline mode."""
312310
chunk = mocker.Mock()
313311
chunk.content = "Test content"
@@ -320,10 +318,11 @@ def test_convert_with_metadata_offline(self, mocker) -> None: # type: ignore[no
320318
assert result[0].content == "Test content"
321319
assert result[0].source == constants.OKP_RAG_ID
322320
assert result[0].score == 0.85
321+
assert result[0].attributes is not None
323322
assert "doc_url" in result[0].attributes
324323
assert "parent_123" in result[0].attributes["doc_url"]
325324

326-
def test_convert_with_metadata_online(self, mocker) -> None: # type: ignore[no-untyped-def]
325+
def test_convert_with_metadata_online(self, mocker: MockerFixture) -> None:
327326
"""Test conversion with metadata in online mode."""
328327
chunk = mocker.Mock()
329328
chunk.content = "Test content"
@@ -333,9 +332,10 @@ def test_convert_with_metadata_online(self, mocker) -> None: # type: ignore[no-
333332
result = _convert_solr_chunks_to_rag_format([chunk], [0.75], offline=False)
334333

335334
assert len(result) == 1
335+
assert result[0].attributes is not None
336336
assert result[0].attributes["doc_url"] == "https://example.com/doc"
337337

338-
def test_convert_with_chunk_metadata(self, mocker) -> None: # type: ignore[no-untyped-def]
338+
def test_convert_with_chunk_metadata(self, mocker: MockerFixture) -> None:
339339
"""Test conversion with chunk_metadata object."""
340340
chunk_meta = mocker.Mock()
341341
chunk_meta.document_id = "doc_456"
@@ -348,9 +348,10 @@ def test_convert_with_chunk_metadata(self, mocker) -> None: # type: ignore[no-u
348348
result = _convert_solr_chunks_to_rag_format([chunk], [0.9], offline=True)
349349

350350
assert len(result) == 1
351+
assert result[0].attributes is not None
351352
assert result[0].attributes["document_id"] == "doc_456"
352353

353-
def test_convert_multiple_chunks(self, mocker) -> None: # type: ignore[no-untyped-def]
354+
def test_convert_multiple_chunks(self, mocker: MockerFixture) -> None:
354355
"""Test conversion of multiple chunks."""
355356
chunk1 = mocker.Mock()
356357
chunk1.content = "Content 1"
@@ -377,7 +378,7 @@ class TestFetchByokRag:
377378
"""Tests for _fetch_byok_rag async function."""
378379

379380
@pytest.mark.asyncio
380-
async def test_byok_no_inline_ids(self, mocker) -> None: # type: ignore[no-untyped-def]
381+
async def test_byok_no_inline_ids(self, mocker: MockerFixture) -> None:
381382
"""Test when no inline BYOK sources are configured."""
382383
config_mock = mocker.Mock(spec=AppConfig)
383384
config_mock.configuration.rag.inline = []
@@ -392,7 +393,7 @@ async def test_byok_no_inline_ids(self, mocker) -> None: # type: ignore[no-unty
392393
client_mock.vector_io.query.assert_not_called()
393394

394395
@pytest.mark.asyncio
395-
async def test_byok_enabled_success(self, mocker) -> None: # type: ignore[no-untyped-def]
396+
async def test_byok_enabled_success(self, mocker: MockerFixture) -> None:
396397
"""Test successful BYOK RAG fetch when inline IDs are configured."""
397398
# Mock configuration
398399
config_mock = mocker.Mock(spec=AppConfig)
@@ -430,8 +431,8 @@ async def test_byok_enabled_success(self, mocker) -> None: # type: ignore[no-un
430431
assert len(referenced_docs) > 0
431432

432433
@pytest.mark.asyncio
433-
async def test_user_facing_ids_translated_to_internal_ids( # type: ignore[no-untyped-def]
434-
self, mocker
434+
async def test_user_facing_ids_translated_to_internal_ids(
435+
self, mocker: MockerFixture
435436
) -> None:
436437
"""Test that user-facing rag_ids (vector_store_ids) are translated to llama-stack ids."""
437438
config_mock = mocker.Mock(spec=AppConfig)
@@ -466,8 +467,8 @@ async def test_user_facing_ids_translated_to_internal_ids( # type: ignore[no-un
466467
)
467468

468469
@pytest.mark.asyncio
469-
async def test_multiple_user_facing_ids_each_translated( # type: ignore[no-untyped-def]
470-
self, mocker
470+
async def test_multiple_user_facing_ids_each_translated(
471+
self, mocker: MockerFixture
471472
) -> None:
472473
"""Test that multiple user-facing rag_ids are each translated to their vector_store_id."""
473474
config_mock = mocker.Mock(spec=AppConfig)
@@ -517,7 +518,7 @@ class TestFetchSolrRag:
517518
"""Tests for _fetch_solr_rag async function."""
518519

519520
@pytest.mark.asyncio
520-
async def test_solr_disabled(self, mocker) -> None: # type: ignore[no-untyped-def]
521+
async def test_solr_disabled(self, mocker: MockerFixture) -> None:
521522
"""Test when Solr is disabled."""
522523
config_mock = mocker.Mock(spec=AppConfig)
523524
config_mock.inline_solr_enabled = False
@@ -531,7 +532,7 @@ async def test_solr_disabled(self, mocker) -> None: # type: ignore[no-untyped-d
531532
client_mock.vector_io.query.assert_not_called()
532533

533534
@pytest.mark.asyncio
534-
async def test_solr_enabled_success(self, mocker) -> None: # type: ignore[no-untyped-def]
535+
async def test_solr_enabled_success(self, mocker: MockerFixture) -> None:
535536
"""Test successful Solr RAG fetch."""
536537
# Mock configuration
537538
config_mock = mocker.Mock(spec=AppConfig)
@@ -566,7 +567,7 @@ class TestBuildRagContext:
566567
"""Tests for build_rag_context async function."""
567568

568569
@pytest.mark.asyncio
569-
async def test_both_sources_disabled(self, mocker) -> None: # type: ignore[no-untyped-def]
570+
async def test_both_sources_disabled(self, mocker: MockerFixture) -> None:
570571
"""Test when both BYOK inline and Solr inline are not configured."""
571572
config_mock = mocker.Mock(spec=AppConfig)
572573
config_mock.configuration.rag.inline = []
@@ -582,7 +583,7 @@ async def test_both_sources_disabled(self, mocker) -> None: # type: ignore[no-u
582583
assert context.referenced_documents == []
583584

584585
@pytest.mark.asyncio
585-
async def test_byok_enabled_only(self, mocker) -> None: # type: ignore[no-untyped-def]
586+
async def test_byok_enabled_only(self, mocker: MockerFixture) -> None:
586587
"""Test when only inline BYOK is configured."""
587588
# Mock configuration
588589
config_mock = mocker.Mock(spec=AppConfig)

0 commit comments

Comments
 (0)