Debian Codegraph @

tests/test_chapters.py

raw
1 from fractions import Fraction
2
3 import av
4
5 from .common import fate_suite
6
7
8 def test_chapters() -> None:
9 expected = [
10 {
11 "id": 1,
12 "start": 0,
13 "end": 5000,
14 "time_base": Fraction(1, 1000),
15 "metadata": {"title": "start"},
16 },
17 {
18 "id": 2,
19 "start": 5000,
20 "end": 10500,
21 "time_base": Fraction(1, 1000),
22 "metadata": {"title": "Five Seconds"},
23 },
24 {
25 "id": 3,
26 "start": 10500,
27 "end": 15000,
28 "time_base": Fraction(1, 1000),
29 "metadata": {"title": "Ten point 5 seconds"},
30 },
31 {
32 "id": 4,
33 "start": 15000,
34 "end": 19849,
35 "time_base": Fraction(1, 1000),
36 "metadata": {"title": "15 sec - over soon"},
37 },
38 ]
39 path = fate_suite("vorbis/vorbis_chapter_extension_demo.ogg")
40 with av.open(path) as container:
41 assert container.chapters() == expected
42
43
44 def test_set_chapters() -> None:
45 chapters: list[av.container.Chapter] = [
46 {
47 "id": 1,
48 "start": 0,
49 "end": 5000,
50 "time_base": Fraction(1, 1000),
51 "metadata": {"title": "start"},
52 }
53 ]
54
55 path = fate_suite("h264/interlaced_crop.mp4")
56 with av.open(path) as container:
57 container.set_chapters(chapters)
58 assert container.chapters() == chapters
59
60
61 def test_set_chapters_empty() -> None:
62 path = fate_suite("vorbis/vorbis_chapter_extension_demo.ogg")
63 with av.open(path) as container:
64 assert len(container.chapters()) == 4
65 container.set_chapters([])
66 assert container.chapters() == []