repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import hashlib |
| #2 | from unittest.mock import MagicMock, Mock, patch |
| #3 | |
| #4 | import pytest |
| #5 | |
| #6 | from embedchain.loaders.youtube_video import YoutubeVideoLoader |
| #7 | |
| #8 | |
| #9 | @pytest.fixture |
| #10 | def youtube_video_loader(): |
| #11 | return YoutubeVideoLoader() |
| #12 | |
| #13 | |
| #14 | def test_load_data(youtube_video_loader): |
| #15 | video_url = "https://www.youtube.com/watch?v=VIDEO_ID" |
| #16 | mock_loader = Mock() |
| #17 | mock_page_content = "This is a YouTube video content." |
| #18 | mock_loader.load.return_value = [ |
| #19 | MagicMock( |
| #20 | page_content=mock_page_content, |
| #21 | metadata={"url": video_url, "title": "Test Video"}, |
| #22 | ) |
| #23 | ] |
| #24 | |
| #25 | mock_transcript = [{"text": "sample text", "start": 0.0, "duration": 5.0}] |
| #26 | |
| #27 | with patch("embedchain.loaders.youtube_video.YoutubeLoader.from_youtube_url", return_value=mock_loader), patch( |
| #28 | "embedchain.loaders.youtube_video.YouTubeTranscriptApi.get_transcript", return_value=mock_transcript |
| #29 | ): |
| #30 | result = youtube_video_loader.load_data(video_url) |
| #31 | |
| #32 | expected_doc_id = hashlib.sha256((mock_page_content + video_url).encode()).hexdigest() |
| #33 | |
| #34 | assert result["doc_id"] == expected_doc_id |
| #35 | |
| #36 | expected_data = [ |
| #37 | { |
| #38 | "content": "This is a YouTube video content.", |
| #39 | "meta_data": {"url": video_url, "title": "Test Video", "transcript": "Unavailable"}, |
| #40 | } |
| #41 | ] |
| #42 | |
| #43 | assert result["data"] == expected_data |
| #44 | |
| #45 | |
| #46 | def test_load_data_with_empty_doc(youtube_video_loader): |
| #47 | video_url = "https://www.youtube.com/watch?v=VIDEO_ID" |
| #48 | mock_loader = Mock() |
| #49 | mock_loader.load.return_value = [] |
| #50 | |
| #51 | with patch("embedchain.loaders.youtube_video.YoutubeLoader.from_youtube_url", return_value=mock_loader): |
| #52 | with pytest.raises(ValueError): |
| #53 | youtube_video_loader.load_data(video_url) |
| #54 |