|
22 | 22 | SemanticScholarProvider, |
23 | 23 | ) |
24 | 24 | from paperqa.clients.client_models import MetadataPostProcessor, MetadataProvider |
| 25 | +from paperqa.clients.exceptions import DOINotFoundError |
25 | 26 | from paperqa.clients.journal_quality import ( |
26 | 27 | DEFAULT_JOURNAL_QUALITY_CSV_PATH, |
27 | 28 | JournalQualityPostProcessor, |
28 | 29 | ) |
29 | 30 | from paperqa.clients.openalex import OpenAlexProvider, reformat_name |
30 | 31 | from paperqa.clients.retractions import RetractionDataPostProcessor |
| 32 | +from paperqa.clients.semantic_scholar import s2_title_search |
31 | 33 | from paperqa.types import SOURCE_QUALITY_MESSAGES, DocDetails |
32 | 34 |
|
33 | 35 | # Use to avoid flaky tests every time citation count changes |
@@ -379,6 +381,32 @@ async def test_client_os_error() -> None: |
379 | 381 | assert mock_get.call_count >= 1, "Expected the exception to have been thrown" |
380 | 382 |
|
381 | 383 |
|
| 384 | +@pytest.mark.asyncio |
| 385 | +@pytest.mark.parametrize( |
| 386 | + "mock_return_data", |
| 387 | + [ |
| 388 | + pytest.param({"data": []}, id="empty-data-list"), |
| 389 | + ], |
| 390 | +) |
| 391 | +async def test_s2_title_search_edge_cases(mock_return_data: dict) -> None: |
| 392 | + async with httpx_aiohttp.HttpxAiohttpClient() as http_client: |
| 393 | + with patch( |
| 394 | + "paperqa.clients.semantic_scholar._s2_get_with_retrying", |
| 395 | + return_value=mock_return_data, |
| 396 | + ): |
| 397 | + with pytest.raises(DOINotFoundError): |
| 398 | + await s2_title_search("some title", client=http_client) |
| 399 | + |
| 400 | + |
| 401 | +@pytest.mark.vcr |
| 402 | +@pytest.mark.asyncio |
| 403 | +async def test_s2_title_search_empty_data() -> None: |
| 404 | + """Confirm an S2 match response with empty data raises DOINotFoundError.""" |
| 405 | + async with httpx_aiohttp.HttpxAiohttpClient() as http_client: |
| 406 | + with pytest.raises(DOINotFoundError): |
| 407 | + await s2_title_search("empty results edge case query", client=http_client) |
| 408 | + |
| 409 | + |
382 | 410 | @pytest.mark.vcr |
383 | 411 | @pytest.mark.asyncio |
384 | 412 | async def test_bad_dois() -> None: |
|
0 commit comments