Skip to content

test(tools): comprehensive test suite for web_search module (+31 tests) - #168

Open
manus-use wants to merge 1 commit into
mainfrom
test/web-search
Open

test(tools): comprehensive test suite for web_search module (+31 tests)#168
manus-use wants to merge 1 commit into
mainfrom
test/web-search

Conversation

@manus-use

Copy link
Copy Markdown
Owner

Summary

Comprehensive test suite for the web_search module (src/manus_agent/tools/web_search.py), which provides the web search capability used by the agent for information gathering.

Test Coverage (31 tests)

SearchEngine base class — 1 test

  • Abstract search() raises NotImplementedError

DuckDuckGoSearch — 7 tests

  • Async search correctly delegates to synchronous _search_sync
  • Result formatting from DuckDuckGo raw response (href + link key variants)
  • Empty results handled gracefully
  • max_results parameter correctly passed to DDGS
  • Missing fields in raw results default to empty strings
  • ImportError raised when duckduckgo-search package not installed

GoogleSearch — 6 tests

  • Credential initialization (api_key, cx)
  • ValueError raised when API key or CX missing
  • Empty string credentials also raise
  • Valid credentials return empty list (placeholder implementation)

get_search_engine factory — 5 tests

  • Config-driven selection: "duckduckgo"DuckDuckGoSearch
  • Config-driven selection: "google"GoogleSearch
  • Unknown engine name falls back to DuckDuckGoSearch
  • Direct config argument accepted (bypasses Config.from_file())
  • Singleton caching: repeated calls return same instance

web_search_async — 4 tests

  • Successful search returns properly formatted results
  • Custom max_results override works
  • Uses config's tools.max_search_results as default
  • Exceptions caught and returned as error result structure

web_search (sync tool) — 5 tests

  • Uses _search_sync method when available (avoids event loop)
  • Custom max_results passed through
  • Exceptions caught and returned as error result
  • Falls back to async path when engine lacks _search_sync
  • Empty results returned as empty list

Backward compatibility + structure — 3 tests

  • web_search_sync is an alias for web_search
  • All results contain required keys (title, url, snippet)
  • All result values are strings

Technical Notes

  • All tests are 100% mocked — no real HTTP calls or search API usage
  • Singleton state properly reset between tests via setup_method
  • Async tests use explicit event loops (no deprecation warnings)
  • Tests document both the DuckDuckGo and Google code paths

Files Changed

  • tests/test_web_search.py — new test file (31 tests)

Add tests for the web_search module covering:

SearchEngine base class (1 test):
- Verifies NotImplementedError for abstract search method

DuckDuckGoSearch (7 tests):
- Async-to-sync delegation
- Formatted result structure (href/link key variants)
- Empty results handling
- max_results parameter passing
- Missing field defaults (empty strings)
- ImportError when duckduckgo-search not installed

GoogleSearch (6 tests):
- Credential initialization
- ValueError when API key or CX missing
- Empty credentials rejection
- Placeholder behavior with valid credentials

get_search_engine factory (5 tests):
- Config-driven engine selection (duckduckgo, google, unknown)
- Direct config argument passing
- Singleton caching behavior

web_search_async (4 tests):
- Success with formatted results
- Custom max_results override
- Config default max_results usage
- Error returns Search Error result

web_search sync tool (5 tests):
- Direct _search_sync method usage
- Custom max_results
- Error handling returns error result
- Fallback to async when no _search_sync method
- Empty results

Backward compatibility + structure (3 tests):
- web_search_sync alias verification
- Result keys (title, url, snippet)
- Result value types (all strings)

All tests 100% mocked — no real HTTP calls or search API usage.
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.

1 participant