-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_plugins.py
More file actions
68 lines (49 loc) · 1.83 KB
/
test_plugins.py
File metadata and controls
68 lines (49 loc) · 1.83 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import logging
from ffmpegio import plugins
from ffmpegio.utils import prod
logging.basicConfig(level=logging.INFO)
def test_rawdata_bytes():
plugins.use("read_bytes")
hook = plugins.get_hook()
dtype = "|u1"
shape = (2, 2, 3)
b = b"\0" * prod(shape)
data = hook.bytes_to_video(b=b, dtype=dtype, shape=shape, squeeze=False)
assert data["buffer"] == b
assert data["dtype"] == dtype
assert data["shape"][1:] == shape
assert hook.video_info(obj=data) == (shape, dtype)
assert hook.video_bytes(obj=data) == b
data = hook.bytes_to_video(b=b, dtype=dtype, shape=shape, squeeze=True)
assert data["shape"] == shape
dtype = "<f4"
shape = (2,)
b = b"\0" * (1024 * prod(shape))
data = hook.bytes_to_audio(b=b, dtype=dtype, shape=shape, squeeze=False)
assert data["buffer"] == b
assert data["dtype"] == dtype
assert data["shape"][1:] == shape
assert hook.audio_info(obj=data) == (shape, dtype)
assert hook.audio_bytes(obj=data) == b
def test_use():
import numpy as np
plugins.use("read_numpy")
assert plugins.using("video") == "read_numpy"
assert plugins.using("audio") == "read_numpy"
dtype = "|u1"
shape = (2, 2, 3)
b = b"\0" * prod(shape)
hook = plugins.get_hook()
data = hook.bytes_to_video(b=b, dtype=dtype, shape=shape, squeeze=False)
assert isinstance(data, np.ndarray)
plugins.use("read_bytes")
assert plugins.using("video") == "read_bytes"
assert plugins.using("audio") == "read_bytes"
hook = plugins.get_hook()
data = hook.bytes_to_video(b=b, dtype=dtype, shape=shape, squeeze=False)
assert isinstance(data, dict)
plugins.use("read_pillow")
assert plugins.using("video") == "read_pillow"
assert plugins.using("audio") != "read_pillow"
if __name__ == "__main__":
print(plugins.pm.get_plugins())