Add pytest coverage for new LiteratureFetcher fallback methods#70
Merged
Conversation
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>
There was a problem hiding this comment.
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.
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Suite total: 102 → 121 passing, 9 skipped.
Test plan
🤖 Generated with Claude Code