import tempfile import pytest from langchain_community.tools import DuckDuckGoSearchRun from tools import GetYouTubeTranscript, get_wikipedia_page @pytest.fixture def yt(): return GetYouTubeTranscript() @pytest.fixture 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