-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_python_library.py
127 lines (94 loc) · 3.81 KB
/
test_python_library.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import vidformer as vf
from fractions import Fraction
ENDPOINT = "http://localhost:8080/v2"
API_KEY = "test"
def test_connect():
server = vf.IgniServer(ENDPOINT, API_KEY)
def test_create_source():
server = vf.IgniServer(ENDPOINT, API_KEY)
tos = server.create_source("../tos_720p.mp4", 0, "fs", {"root": "."})
assert isinstance(tos, vf.IgniSource)
assert len(tos) == 17616
assert len(tos.ts()) == 17616
for t in tos.ts():
assert isinstance(t, Fraction)
def test_source():
server = vf.IgniServer(ENDPOINT, API_KEY)
# delete all specs first (since they depend on sources)
specs = server.list_specs()
for spec in specs:
server.delete_spec(spec)
# delete all sources first
sources = server.list_sources()
for source in sources:
server.delete_source(source)
# Get a source which doesn't exist
tos = server.source("../tos_720p.mp4", 0, "fs", {"root": "."})
assert isinstance(tos, vf.IgniSource)
# Get a source which already exists
tos2 = server.source("../tos_720p.mp4", 0, "fs", {"root": "."})
assert isinstance(tos2, vf.IgniSource)
assert tos.id() == tos2.id()
# check only one source exists
sources = server.list_sources()
assert len(sources) == 1
def test_list_sources():
server = vf.IgniServer(ENDPOINT, API_KEY)
tos = server.create_source("../tos_720p.mp4", 0, "fs", {"root": "."})
sources = server.list_sources()
for source in sources:
assert isinstance(source, str)
assert tos.id() in sources
def test_search_source():
server = vf.IgniServer(ENDPOINT, API_KEY)
tos = server.create_source("../tos_720p.mp4", 0, "fs", {"root": "."})
matching_sources = server.search_source("../tos_720p.mp4", 0, "fs", {"root": "."})
assert type(matching_sources) == list
for source in matching_sources:
assert isinstance(source, str)
assert tos.id() in matching_sources
def test_delete_source():
server = vf.IgniServer(ENDPOINT, API_KEY)
tos = server.create_source("../tos_720p.mp4", 0, "fs", {"root": "."})
server.delete_source(tos.id())
sources = server.list_sources()
assert tos.id() not in sources
def test_create_spec():
server = vf.IgniServer(ENDPOINT, API_KEY)
segment_legnth = Fraction(2, 1)
spec_id = server.create_spec(1920, 1080, "yuv420p", segment_legnth, Fraction(30, 1))
assert isinstance(spec_id, vf.IgniSpec)
def test_list_specs():
server = vf.IgniServer(ENDPOINT, API_KEY)
spec = server.create_spec(1920, 1080, "yuv420p", Fraction(2, 1), Fraction(30, 1))
specs = server.list_specs()
for s in specs:
assert isinstance(s, str)
assert spec.id() in specs
def test_delete_spec():
server = vf.IgniServer(ENDPOINT, API_KEY)
spec = server.create_spec(1920, 1080, "yuv420p", Fraction(2, 1), Fraction(30, 1))
server.delete_spec(spec.id())
specs = server.list_specs()
assert spec.id() not in specs
def test_push_spec_part():
server = vf.IgniServer(ENDPOINT, API_KEY)
tos = server.create_source("../tos_720p.mp4", 0, "fs", {"root": "."})
spec_id = server.create_spec(1920, 1080, "yuv420p", Fraction(2, 1), Fraction(30, 1))
frames = []
for i in range(100):
t = Fraction(i, 30)
f = tos.iloc[i]
frames.append((t, f))
server.push_spec_part(spec_id, 0, frames, True)
def test_push_spec_part_multiple():
server = vf.IgniServer(ENDPOINT, API_KEY)
tos = server.create_source("../tos_720p.mp4", 0, "fs", {"root": "."})
spec_id = server.create_spec(1920, 1080, "yuv420p", Fraction(2, 1), Fraction(30, 1))
for part in range(10):
frames = []
for i in range(10):
t = Fraction(i, 30) + Fraction(part, 3)
f = tos.iloc[i]
frames.append((t, f))
server.push_spec_part(spec_id, part * 10, frames, part == 9)