2022-12-30 13:06:57 +00:00
|
|
|
"""Integration test for Google Search API Wrapper."""
|
2024-02-10 00:13:30 +00:00
|
|
|
|
2023-12-11 21:53:30 +00:00
|
|
|
from langchain_community.utilities.google_search import GoogleSearchAPIWrapper
|
2022-12-30 13:06:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_call() -> None:
|
|
|
|
"""Test that call gives the correct answer."""
|
2024-05-13 18:55:07 +00:00
|
|
|
search = GoogleSearchAPIWrapper() # type: ignore[call-arg]
|
2022-12-30 13:06:57 +00:00
|
|
|
output = search.run("What was Obama's first name?")
|
|
|
|
assert "Barack Hussein Obama II" in output
|
2023-02-17 21:04:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_no_result_call() -> None:
|
|
|
|
"""Test that call gives no result."""
|
2024-05-13 18:55:07 +00:00
|
|
|
search = GoogleSearchAPIWrapper() # type: ignore[call-arg]
|
2023-02-17 21:04:02 +00:00
|
|
|
output = search.run(
|
|
|
|
"NORESULTCALL_NORESULTCALL_NORESULTCALL_NORESULTCALL_NORESULTCALL_NORESULTCALL"
|
|
|
|
)
|
2024-02-10 00:13:30 +00:00
|
|
|
print(type(output)) # noqa: T201
|
2023-02-17 21:04:02 +00:00
|
|
|
assert "No good Google Search Result was found" == output
|
2023-07-02 07:18:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_result_with_params_call() -> None:
|
|
|
|
"""Test that call gives the correct answer with extra params."""
|
2024-05-13 18:55:07 +00:00
|
|
|
search = GoogleSearchAPIWrapper() # type: ignore[call-arg]
|
2023-07-02 07:18:38 +00:00
|
|
|
output = search.results(
|
|
|
|
query="What was Obama's first name?",
|
|
|
|
num_results=5,
|
|
|
|
search_params={"cr": "us", "safe": "active"},
|
|
|
|
)
|
|
|
|
assert len(output)
|