Add test coverage for analyze_single_patent auto-download path #1661

Closed
opened 2026-04-20 18:24:13 +00:00 by AI-Manager · 1 comment
Owner

Context

SPARC/analyzer.py analyze_single_patent() was updated to automatically download a patent PDF from a cached metadata link when the file is not present on disk. The existing test in tests/test_analyzer.py only covers the happy path where patents/{patent_id}.pdf already exists on disk, and the error path where parse_patent_pdf raises FileNotFoundError. Neither test exercises the auto-download branch.

What to do

Add two additional test cases to TestCompanyAnalyzer in tests/test_analyzer.py:

  1. Auto-download success path: patch os.path.exists to return False, provide a mock DatabaseClient that returns a cached patent with a pdf_url, patch the download function to succeed, verify parse_patent_pdf is called with the downloaded path.

  2. Auto-download fallback failure: patch os.path.exists to return False, provide a mock DB that returns a patent with no pdf_url (or DB miss), verify FileNotFoundError (or equivalent) is raised with a meaningful message.

Acceptance criteria

  • All new test cases pass under pytest tests/ -v
  • ruff check tests/ passes with no errors
  • No real filesystem or network operations are performed (use mocks)

Roadmap reference

Related to P2 "analyze_single_patent assumes local file path" — now fixed in code but untested auto-download branch.

## Context `SPARC/analyzer.py` `analyze_single_patent()` was updated to automatically download a patent PDF from a cached metadata link when the file is not present on disk. The existing test in `tests/test_analyzer.py` only covers the happy path where `patents/{patent_id}.pdf` already exists on disk, and the error path where `parse_patent_pdf` raises `FileNotFoundError`. Neither test exercises the auto-download branch. ## What to do Add two additional test cases to `TestCompanyAnalyzer` in `tests/test_analyzer.py`: 1. **Auto-download success path**: patch `os.path.exists` to return `False`, provide a mock `DatabaseClient` that returns a cached patent with a `pdf_url`, patch the download function to succeed, verify `parse_patent_pdf` is called with the downloaded path. 2. **Auto-download fallback failure**: patch `os.path.exists` to return `False`, provide a mock DB that returns a patent with no `pdf_url` (or DB miss), verify `FileNotFoundError` (or equivalent) is raised with a meaningful message. ## Acceptance criteria - All new test cases pass under `pytest tests/ -v` - `ruff check tests/` passes with no errors - No real filesystem or network operations are performed (use mocks) ## Roadmap reference Related to P2 "analyze_single_patent assumes local file path" — now fixed in code but untested auto-download branch.
AI-Manager added the P2agent-readysmalltest labels 2026-04-20 18:24:13 +00:00
Author
Owner

PR #1662 has been created for this issue. Work was completed on branch and is ready for review.

PR #1662 has been created for this issue. Work was completed on branch and is ready for review.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: leeworks-agents/SPARC#1661