forked from PyAV-Org/PyAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python_io.py
More file actions
98 lines (68 loc) · 2.76 KB
/
Copy pathtest_python_io.py
File metadata and controls
98 lines (68 loc) · 2.76 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
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
from __future__ import division
import av
from .common import MethodLogger, TestCase, fate_suite
from .test_encode import assert_rgb_rotate, write_rgb_rotate
try:
from cStringIO import StringIO
except ImportError:
from io import BytesIO as StringIO
class NonSeekableBuffer:
def __init__(self, data):
self.data = data
def read(self, n):
data = self.data[0:n]
self.data = self.data[n:]
return data
class TestPythonIO(TestCase):
def test_reading(self):
with open(fate_suite('mpeg2/mpeg2_field_encoding.ts'), 'rb') as fh:
wrapped = MethodLogger(fh)
container = av.open(wrapped)
self.assertEqual(container.format.name, 'mpegts')
self.assertEqual(container.format.long_name, "MPEG-TS (MPEG-2 Transport Stream)")
self.assertEqual(len(container.streams), 1)
self.assertEqual(container.size, 800000)
self.assertEqual(container.metadata, {})
# Make sure it did actually call "read".
reads = wrapped._filter('read')
self.assertTrue(reads)
def test_reading_no_seek(self):
with open(fate_suite('mpeg2/mpeg2_field_encoding.ts'), 'rb') as fh:
data = fh.read()
buf = NonSeekableBuffer(data)
wrapped = MethodLogger(buf)
container = av.open(wrapped)
self.assertEqual(container.format.name, 'mpegts')
self.assertEqual(container.format.long_name, "MPEG-TS (MPEG-2 Transport Stream)")
self.assertEqual(len(container.streams), 1)
self.assertEqual(container.metadata, {})
# Make sure it did actually call "read".
reads = wrapped._filter('read')
self.assertTrue(reads)
def test_basic_errors(self):
self.assertRaises(Exception, av.open, None)
self.assertRaises(Exception, av.open, None, 'w')
def test_writing(self):
path = self.sandboxed('writing.mov')
with open(path, 'wb') as fh:
wrapped = MethodLogger(fh)
output = av.open(wrapped, 'w', 'mov')
write_rgb_rotate(output)
output.close()
fh.close()
# Make sure it did actually write.
writes = wrapped._filter('write')
self.assertTrue(writes)
# Standard assertions.
assert_rgb_rotate(self, av.open(path))
def test_buffer_read_write(self):
buffer_ = StringIO()
wrapped = MethodLogger(buffer_)
write_rgb_rotate(av.open(wrapped, 'w', 'mp4'))
# Make sure it did actually write.
writes = wrapped._filter('write')
self.assertTrue(writes)
self.assertTrue(buffer_.tell())
# Standard assertions.
buffer_.seek(0)
assert_rgb_rotate(self, av.open(buffer_))