Skip to content

Commit f44b40b

Browse files
committed
Reduce test_cli.py duplication further
Route the pdf-download and auto-enrich tests through the shared patched_pipeline fixture, and delete the now-redundant _fake_search_with_papers helper (it duplicated the fixture's run_search / shutdown stub). test_cli.py 926 -> 848 lines across this pass; the only remaining fake_run_search definitions are the fixture and _patch_search (which legitimately takes custom papers with controlled pdf_url).
1 parent 98b34d4 commit f44b40b

1 file changed

Lines changed: 11 additions & 54 deletions

File tree

tests/test_cli.py

Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -353,61 +353,33 @@ def test_cli_top_tier_filter_off_by_default(tmp_path, patched_pipeline):
353353
assert patched_pipeline["query"].top_tier_only is True
354354

355355

356-
def test_cli_default_triggers_pdf_download(tmp_path, monkeypatch, sample_papers):
356+
def test_cli_default_triggers_pdf_download(tmp_path, monkeypatch, patched_pipeline):
357357
"""Default flag set should invoke download_pdfs; --no-pdf disables it."""
358358
calls: list[str] = []
359359

360-
async def fake_run_search(query: Query, **_kwargs) -> PaperCollection:
361-
return PaperCollection(query=query, papers=tuple(sample_papers))
362-
363-
async def fake_shutdown() -> None:
364-
return None
365-
366-
async def fake_download(_collection, _out_dir):
360+
async def fake_download(_collection, _out_dir): # NOSONAR async stub
367361
calls.append("called")
368362
return []
369363

370-
monkeypatch.setattr(cli_module, "run_search", fake_run_search)
371-
monkeypatch.setattr(cli_module, "shutdown_clients", fake_shutdown)
372364
monkeypatch.setattr(cli_module, "download_pdfs", fake_download)
373-
374365
code = cli_module.main(
375-
[
376-
"--query", "x",
377-
"--source", "arxiv",
378-
"--out", str(tmp_path),
379-
"--export", "bib",
380-
]
366+
["--query", "x", "--source", "arxiv", "--out", str(tmp_path), "--export", "bib"]
381367
)
382368
assert code == 0
383369
assert calls == ["called"]
384370

385371

386-
def test_cli_no_pdf_flag_skips_download(tmp_path, monkeypatch, sample_papers):
372+
def test_cli_no_pdf_flag_skips_download(tmp_path, monkeypatch, patched_pipeline):
387373
calls: list[str] = []
388374

389-
async def fake_run_search(query: Query, **_kwargs) -> PaperCollection:
390-
return PaperCollection(query=query, papers=tuple(sample_papers))
391-
392-
async def fake_shutdown() -> None:
393-
return None
394-
395-
async def fake_download(_collection, _out_dir):
375+
async def fake_download(_collection, _out_dir): # NOSONAR async stub
396376
calls.append("called")
397377
return []
398378

399-
monkeypatch.setattr(cli_module, "run_search", fake_run_search)
400-
monkeypatch.setattr(cli_module, "shutdown_clients", fake_shutdown)
401379
monkeypatch.setattr(cli_module, "download_pdfs", fake_download)
402-
403380
code = cli_module.main(
404-
[
405-
"--query", "x",
406-
"--source", "arxiv",
407-
"--no-pdf",
408-
"--out", str(tmp_path),
409-
"--export", "bib",
410-
]
381+
["--query", "x", "--source", "arxiv", "--no-pdf",
382+
"--out", str(tmp_path), "--export", "bib"]
411383
)
412384
assert code == 0
413385
assert calls == []
@@ -734,21 +706,9 @@ async def fake_enrich(collection, language=None, model=None): # noqa: ARG001
734706
return calls
735707

736708

737-
def _fake_search_with_papers(monkeypatch, sample_papers):
738-
async def fake_run_search(query, **_kwargs):
739-
return PaperCollection(query=query, papers=tuple(sample_papers))
740-
741-
async def fake_shutdown():
742-
return None
743-
744-
monkeypatch.setattr(cli_module, "run_search", fake_run_search)
745-
monkeypatch.setattr(cli_module, "shutdown_clients", fake_shutdown)
746-
747-
748-
def test_cli_auto_enriches_when_api_key_set(tmp_path, monkeypatch, sample_papers):
709+
def test_cli_auto_enriches_when_api_key_set(tmp_path, monkeypatch, patched_pipeline):
749710
"""ANTHROPIC_API_KEY in env + no --lightweight = auto-enrich fires."""
750711
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-key")
751-
_fake_search_with_papers(monkeypatch, sample_papers)
752712
calls = _stub_enrich_collection(monkeypatch)
753713
code = cli_module.main(
754714
["--query", "x", "--source", "arxiv", "--out", str(tmp_path), "--export", "bib"]
@@ -757,10 +717,9 @@ def test_cli_auto_enriches_when_api_key_set(tmp_path, monkeypatch, sample_papers
757717
assert calls == ["called"]
758718

759719

760-
def test_cli_lightweight_skips_auto_enrich(tmp_path, monkeypatch, sample_papers):
720+
def test_cli_lightweight_skips_auto_enrich(tmp_path, monkeypatch, patched_pipeline):
761721
"""--lightweight wins over the auto-enrich default."""
762722
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-key")
763-
_fake_search_with_papers(monkeypatch, sample_papers)
764723
calls = _stub_enrich_collection(monkeypatch)
765724
code = cli_module.main(
766725
[
@@ -773,10 +732,9 @@ def test_cli_lightweight_skips_auto_enrich(tmp_path, monkeypatch, sample_papers)
773732
assert calls == []
774733

775734

776-
def test_cli_no_key_does_not_auto_enrich(tmp_path, monkeypatch, sample_papers):
735+
def test_cli_no_key_does_not_auto_enrich(tmp_path, monkeypatch, patched_pipeline):
777736
"""No ANTHROPIC_API_KEY → no Anthropic call, lightweight deck."""
778737
monkeypatch.delenv("ANTHROPIC_API_KEY", raising=False)
779-
_fake_search_with_papers(monkeypatch, sample_papers)
780738
calls = _stub_enrich_collection(monkeypatch)
781739
code = cli_module.main(
782740
["--query", "x", "--source", "arxiv", "--out", str(tmp_path), "--export", "bib"]
@@ -785,11 +743,10 @@ def test_cli_no_key_does_not_auto_enrich(tmp_path, monkeypatch, sample_papers):
785743
assert calls == []
786744

787745

788-
def test_cli_explicit_enrich_still_works(tmp_path, monkeypatch, sample_papers):
746+
def test_cli_explicit_enrich_still_works(tmp_path, monkeypatch, patched_pipeline):
789747
"""--enrich runs even without a key in env (the explicit path used to
790748
error inside the API client; here we only check the CLI dispatch)."""
791749
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-key")
792-
_fake_search_with_papers(monkeypatch, sample_papers)
793750
calls = _stub_enrich_collection(monkeypatch)
794751
code = cli_module.main(
795752
[

0 commit comments

Comments
 (0)