From 6b7a3ee97daf1d1720d29423b52fe9fabe295f01 Mon Sep 17 00:00:00 2001 From: Mathias Koehler Date: Wed, 18 Jan 2012 22:11:52 +0100 Subject: [PATCH] Make a test for FFmpegProcess --- setup.cfg | 2 ++ setup.py | 3 +++ test.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b542371 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[upload_docs] +upload-dir = docs/_build/html diff --git a/setup.py b/setup.py index 74fe018..5024430 100755 --- a/setup.py +++ b/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', diff --git a/test.py b/test.py index fc19721..16b3c50 100644 --- a/test.py +++ b/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):