mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
1ed708391e
Fix KeyError 'items' when no result found. ## Problem When no result found for a query, google search crashed with `KeyError 'items'`. ## Solution I added a check for an empty response before accessing the 'items' key. It will handle the case correctly. ## Other my twitter: yakigac (I don't mind even if you don't mention me for this PR. But just because last time my real name was shout out :) )
20 lines
664 B
Python
20 lines
664 B
Python
"""Integration test for Google Search API Wrapper."""
|
|
from langchain.utilities.google_search import GoogleSearchAPIWrapper
|
|
|
|
|
|
def test_call() -> None:
|
|
"""Test that call gives the correct answer."""
|
|
search = GoogleSearchAPIWrapper()
|
|
output = search.run("What was Obama's first name?")
|
|
assert "Barack Hussein Obama II" in output
|
|
|
|
|
|
def test_no_result_call() -> None:
|
|
"""Test that call gives no result."""
|
|
search = GoogleSearchAPIWrapper()
|
|
output = search.run(
|
|
"NORESULTCALL_NORESULTCALL_NORESULTCALL_NORESULTCALL_NORESULTCALL_NORESULTCALL"
|
|
)
|
|
print(type(output))
|
|
assert "No good Google Search Result was found" == output
|