fix(image_search): validate engine parameter and raise ValueError for unsupported values - #97
Merged
vedaant00 merged 2 commits intoAug 5, 2026
Conversation
… unsupported values (fixes mldsveda#94)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #94 by making ImageSearchScraper reject unsupported engine values instead of silently falling back to Bing, and adds regression tests to lock in the behavior.
Changes:
- Validate
engineinImageSearchScraper.scrapeandscrape_asyncand raiseValueErrorfor unsupported values. - Add sync + async unit tests asserting
ValueErroris raised for an invalid engine string.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/pyscrappy/scrapers/image_search.py |
Adds explicit engine validation and errors for unsupported engines in both sync and async paths. |
tests/test_scrapers/test_other.py |
Adds sync/async tests verifying unsupported engines raise ValueError. |
Suppressed comments (2)
src/pyscrappy/scrapers/image_search.py:82
- ValueError messages in other scrapers start with a capital letter (e.g., src/pyscrappy/scrapers/news.py:78, src/pyscrappy/scrapers/spotify.py:66). For consistency, consider capitalizing this message too.
if engine not in ("bing", "google"):
raise ValueError(f"unsupported engine {engine!r}; use 'bing' or 'google'")
tests/test_scrapers/test_other.py:232
- If the ValueError message is capitalized for consistency, this test's regex should be updated to match the new casing.
with pytest.raises(ValueError, match="unsupported engine 'googel'"):
await scraper.scrape_async(query="test", engine="googel")
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Match the sibling scrapers' ValueError casing (news/imdb/youtube start with a capital), update the test regexes to match, and remove the trailing blank line ruff format flagged.
Collaborator
|
Correct fix and good sync+async coverage, thanks @HeaTTap. Pushed a tiny follow-up: capitalized the ValueError to match the other scrapers (news/imdb/youtube) and dropped a trailing blank line for the format check. Green now. |
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.
Fixes #94
Changes
ImageSearchScraper.scrapeandImageSearchScraper.scrape_asyncto validate thatengineis either"bing"or"google".ValueErrorif an unsupported engine string (e.g.,"googel") is provided instead of silently defaulting to Bing.tests/test_scrapers/test_other.pyto verifyValueErroris raised as expected.