Make a test for FFmpegProcess
This commit is contained in:
parent
4d905c1c27
commit
6b7a3ee97d
3
setup.py
3
setup.py
|
|
@ -18,6 +18,7 @@ resulting command.
|
|||
|
||||
"""
|
||||
|
||||
import sys
|
||||
from setuptools import setup
|
||||
|
||||
|
||||
|
|
@ -32,6 +33,8 @@ setup(
|
|||
keywords='Video Convert Ffmpeg',
|
||||
long_description=__doc__,
|
||||
license="BSD",
|
||||
test_suite='test',
|
||||
tests_require='mock>=0.7.2',
|
||||
classifiers=[
|
||||
'Development Status :: 2 - Pre-Alpha',
|
||||
'Intended Audience :: Developers',
|
||||
|
|
|
|||
29
test.py
29
test.py
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
import unittest
|
||||
|
||||
from mock import patch
|
||||
|
||||
from ffmpegwrapper import FFmpeg, Input, Output, \
|
||||
VideoCodec, AudioCodec, VideoFilter
|
||||
from ffmpegwrapper.options import Option
|
||||
|
|
@ -9,6 +11,27 @@ from ffmpegwrapper.options import Option
|
|||
|
||||
class FFmpegTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
patcher = patch('ffmpegwrapper.ffmpeg.Popen')
|
||||
popen = patcher.start()
|
||||
self.instance = popen.return_value
|
||||
|
||||
poll_values = [None] * 80
|
||||
def poll(*args):
|
||||
if len(poll_values) < 1:
|
||||
return 0
|
||||
poll_values.pop(0)
|
||||
self.instance.poll.side_effect = poll
|
||||
|
||||
read_value = list('this is a line\nthis too\n')
|
||||
def read(*args):
|
||||
if len(read_value) > 0:
|
||||
return read_value.pop(0).encode('utf-8')
|
||||
return ''.encode('utf-8')
|
||||
self.instance.stdout.read.side_effect = read
|
||||
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
def test_input_interface(self):
|
||||
input = Input('/old')
|
||||
self.assertEqual(list(input), ['-i', '/old'])
|
||||
|
|
@ -58,6 +81,12 @@ class FFmpegTestCase(unittest.TestCase):
|
|||
ffmpeg = FFmpeg('ffmpeg', input, output)
|
||||
self.assertEqual(list(ffmpeg), ['ffmpeg', '-i', '/old', '/new'])
|
||||
|
||||
with ffmpeg as process:
|
||||
result = list(process.readlines())
|
||||
self.assertEqual(result[0], 'this is a line')
|
||||
self.assertEqual(result[1], 'this too')
|
||||
self.assertEqual(len(result), 2)
|
||||
|
||||
|
||||
class VideoFilterTestCase(unittest.TestCase):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue