-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_transcript.py
More file actions
53 lines (43 loc) · 2.25 KB
/
Copy pathtest_transcript.py
File metadata and controls
53 lines (43 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import contextlib
import io
import subprocess
import sys
import unittest
from pathlib import Path
import transcript
class TranscriptTests(unittest.TestCase):
def test_detects_supported_platforms(self):
self.assertEqual(transcript.detect_platform("https://youtube.com/watch?v=abc"), "youtube")
self.assertEqual(transcript.detect_platform("https://youtu.be/abc"), "youtube")
self.assertEqual(transcript.detect_platform("https://tiktok.com/@user/video/1"), "tiktok")
self.assertEqual(transcript.detect_platform("https://instagram.com/reel/1"), "instagram")
def test_rejects_unsupported_platform(self):
self.assertIsNone(transcript.detect_platform("https://example.com/video"))
def test_extracts_youtube_video_ids(self):
video_id = "abcDEF_123-"
self.assertEqual(transcript.extract_video_id(f"https://youtube.com/watch?v={video_id}"), video_id)
self.assertEqual(transcript.extract_video_id(f"https://youtu.be/{video_id}"), video_id)
self.assertEqual(transcript.extract_video_id(f"https://youtube.com/shorts/{video_id}"), video_id)
self.assertEqual(transcript.extract_video_id(video_id), video_id)
self.assertIsNone(transcript.extract_video_id("not-a-video-id"))
def test_sanitizes_filenames(self):
self.assertEqual(transcript.sanitize_filename(' A <bad>: "title"? '), "A bad title")
self.assertEqual(transcript.sanitize_filename("<>"), "transcript")
self.assertEqual(len(transcript.sanitize_filename("x" * 250)), 200)
def test_unsupported_url_does_not_start_network_work(self):
output = io.StringIO()
with contextlib.redirect_stdout(output):
transcript.process_url("https://example.com/video", Path("."), "base")
self.assertIn("Unrecognized platform", output.getvalue())
def test_cli_help_runs_without_downloading_dependencies(self):
result = subprocess.run(
[sys.executable, "transcript.py", "--help"],
cwd=Path(__file__).parent,
capture_output=True,
text=True,
check=False,
)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("Transcribe YouTube", result.stdout)
if __name__ == "__main__":
unittest.main()