-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_plugins.py
More file actions
51 lines (39 loc) · 1.42 KB
/
test_plugins.py
File metadata and controls
51 lines (39 loc) · 1.42 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
from ffmpegio.utils import prod
from ffmpegio import plugins
def test_rawdata_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")
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")
hook = plugins.get_hook()
data = hook.bytes_to_video(b=b, dtype=dtype, shape=shape, squeeze=False)
assert isinstance(data, dict)
if __name__ == "__main__":
print(plugins.pm.get_plugins())