forked from egao1980/PyAV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python_io.py
More file actions
71 lines (49 loc) · 1.97 KB
/
Copy pathtest_python_io.py
File metadata and controls
71 lines (49 loc) · 1.97 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
from __future__ import division
import math
try:
from cStringIO import StringIO
except ImportError:
from io import BytesIO as StringIO
from .common import *
from .test_encode import write_rgb_rotate, assert_rgb_rotate
from av.video.stream import VideoStream
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_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_))