Skip to content

Add pytest coverage for new LiteratureFetcher fallback methods#70

Merged
realmarcin merged 2 commits into
mainfrom
claude/literature-fetcher-tests
May 18, 2026
Merged

Add pytest coverage for new LiteratureFetcher fallback methods#70
realmarcin merged 2 commits into
mainfrom
claude/literature-fetcher-tests

Conversation

@realmarcin
Copy link
Copy Markdown
Contributor

Summary

Add 19 unit tests covering the four fallback abstract sources added across earlier PRs (#52, #58, #59), plus the shared PMC ID-converter helper and the cache-path helper. Tests mock `requests.Session.get` on the fetcher's own session so no network is required.

What's covered

  • `fetch_openalex_abstract`: inverted-index reconstruction, disk-cache hit, no-abstract record, request exception, case-insensitive DOI prefix stripping
  • `fetch_semantic_scholar_abstract`: successful abstract field, disk-cache hit, null abstract field
  • `fetch_europepmc_abstract`: first-result extraction, empty-results None return, `DOI:` query param shape
  • `fetch_publisher_meta_abstract`: Springer `twitter:description` "Journal -" prefix strip, fallback to `description` meta tag, short-description filter (>80 chars to skip nav text), request exception
  • `fetch_pmcid_for_doi`: numeric ID strip from "PMC..." record, `None` for `status:error` records, `None` for empty records list
  • `_abstract_cache_path`: forward-slash → underscore safe filename encoding

Suite total: 102 → 121 passing, 9 skipped.

Test plan

  • `just test` — 121 passed, 9 skipped, 7 deselected
  • No network calls (verified by mocking `fetcher.session.get` and asserting `mock_get.assert_not_called()` on cache-hit paths)

🤖 Generated with Claude Code

Cover the four new fallback methods added in earlier PRs, plus the
PMC ID-converter helper and the shared cache-path helper. Tests
mock requests.Session.get on the fetcher's own session so no
network is required.

Coverage (19 tests, all passing):
- fetch_openalex_abstract: inverted-index reconstruction, disk
  cache hit, no-abstract record, request exception, case-insensitive
  DOI prefix stripping.
- fetch_semantic_scholar_abstract: successful abstract field, disk
  cache hit, null abstract field.
- fetch_europepmc_abstract: first-result extraction, empty-results
  None return, DOI: query param shape.
- fetch_publisher_meta_abstract: Springer twitter:description
  prefix-strip, fallback to description meta, short-description
  filter (>80 chars to skip nav text), request exception.
- fetch_pmcid_for_doi: numeric id strip from "PMC..." record,
  None for status:error records, None for empty records list.
- _abstract_cache_path: forward-slash to underscore safe filename
  encoding.

Suite total: 102 -> 121 passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 18, 2026 03:04
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit coverage for LiteratureFetcher abstract fallback helpers and cache behavior, improving confidence that these network-backed fallbacks can be tested without real HTTP calls.

Changes:

  • Adds pytest fixtures and mock response helpers.
  • Covers OpenAlex, Semantic Scholar, Europe PMC, publisher meta scraping, PMCID lookup, and cache path behavior.
Comments suppressed due to low confidence (1)

tests/test_literature_fetcher.py:152

  • This line also exceeds the configured 100-character limit enforced by black/ruff, which can make lint checks fail. Please wrap the context manager across multiple lines.
    with patch.object(fetcher.session, "get", return_value=_mock_json_response(payload)) as mock_get:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_literature_fetcher.py Outdated
Wrap the two 101-char `with patch.object(...) as mock_get:` lines so
the file passes the black/ruff 100-char line-length configured in
pyproject.toml. Ran `uv run black tests/test_literature_fetcher.py`
to apply the standard wrapping; the 19 tests still pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@realmarcin realmarcin merged commit 6f6255f into main May 18, 2026
@realmarcin realmarcin deleted the claude/literature-fetcher-tests branch May 18, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants