-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
52 lines (41 loc) · 1.65 KB
/
test.py
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
import unittest
import ujson
from Helper import YoutubeExtractor, ChapterExtractor
class TestYtDlp(unittest.TestCase):
def test_yt_dlp_chapter(self):
# Of course, test link should have chapters.
info = YoutubeExtractor.extract('https://youtu.be/aEctTih1RB8')
assert info.get('chapters', None) is not None
print(f'result: {ujson.dumps(info.get("chapters"), indent=True)}')
class TestChapterExtractor(unittest.TestCase):
def test_chapter_extractor_from_str(self):
ready = [
{
"start_time": 0.0,
"title": "what are chapters",
"end_time": 48.0
},
{
"start_time": 48.0,
"title": "how to add chapters",
"end_time": 140.0
},
{
"start_time": 140.0,
"title": "reasons your chapters might not be working",
"end_time": 287
}
]
chapters = ChapterExtractor.extract_chapter_info(ready)
assert len(chapters) == 3
assert chapters[0].title == 'what are chapters'
assert chapters[1].title == 'how to add chapters'
assert chapters[2].title == 'reasons your chapters might not be working'
assert chapters[0].start_time == 0.0
assert chapters[1].start_time == 48.0
assert chapters[2].start_time == 140.0
assert chapters[0].end_time == 48.0
assert chapters[1].end_time == 140.0
assert chapters[2].end_time == 287.0
def test_chapter_extractor_from_str_with_none(self):
assert ChapterExtractor.extract_chapter_info(None) == []