Download test_tools.py from andrei-sferdian/Agents_Course_Final_Assignment: direct link, hf CLI and curl.
- Browser
- Download file 1.5 kB
-
https://huggingface.co/spaces/andrei-sferdian/Agents_Course_Final_Assignment/resolve/main/test_tools.py
- Command line
-
hf download hf://spaces/andrei-sferdian/Agents_Course_Final_Assignment/test_tools.py
-
curl -L -o test_tools.py https://huggingface.co/spaces/andrei-sferdian/Agents_Course_Final_Assignment/resolve/main/test_tools.py
1.5 kB
| import tempfile | |
| import pytest | |
| from langchain_community.tools import DuckDuckGoSearchRun | |
| from tools import GetYouTubeTranscript, get_wikipedia_page | |
| def yt(): | |
| return GetYouTubeTranscript() | |
| def ddg(): | |
| return DuckDuckGoSearchRun() | |
| def test_valid_youtube_url(yt): | |
| # Use a real YouTube video URL with a publicly available transcript | |
| url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ&ab_channel=RickAstley" # Replace with a valid video ID | |
| result = yt._run(url) | |
| assert ( | |
| "Never gonna give you up" in result | |
| ) # Check for a known part of the transcript | |
| def test_invalid_youtube_url(yt): | |
| url = "https://www.youtube.com/watch?v=" | |
| result = yt._run(url) | |
| assert result == "Video ID not found in the URL" | |
| def test_non_youtube_url(yt): | |
| url = "https://www.example.com" | |
| result = yt._run(url) | |
| assert result == "Video ID not found in the URL" | |
| def test_ddg_search(ddg: DuckDuckGoSearchRun): | |
| query = "Mercedes Sosa live albums" | |
| result = ddg._run(query) | |
| print(result) | |
| assert isinstance(result, str) # Check if the result is a string | |
| def test_wiki_get_content(): | |
| query = "Mercedes Sosa" | |
| content = get_wikipedia_page(query) | |
| temp_file = tempfile.NamedTemporaryFile( | |
| delete=False, mode="w", encoding="utf-8", dir="/tmp" | |
| ) | |
| with open(temp_file.name, "w", encoding="utf-8") as file: | |
| file.write(content) | |
| assert content != "" | |
| assert "Error" not in content | |