From 662727c09795b0869196cef100599cd3c7307659 Mon Sep 17 00:00:00 2001 From: Thomas Fillon Date: Fri, 29 Nov 2013 11:33:53 +0100 Subject: [PATCH] Tests : enable to set test prefix in unit-timeside runTestModule + Encoder : minor changes in webm code --- tests/test_encoding.py | 5 +++-- tests/test_transcoding.py | 14 +++++++------- tests/unit_timeside.py | 17 +++++++++++------ timeside/decoder/core.py | 2 +- timeside/decoder/utils.py | 2 +- timeside/encoder/core.py | 2 +- timeside/encoder/webm.py | 33 +++++++++++++++++++-------------- 7 files changed, 43 insertions(+), 32 deletions(-) diff --git a/tests/test_encoding.py b/tests/test_encoding.py index 693f0c3..5fe617f 100755 --- a/tests/test_encoding.py +++ b/tests/test_encoding.py @@ -10,6 +10,7 @@ from timeside.decoder import ArrayDecoder import os from tools import tmp_file_sink + class TestEncoding(unittest.TestCase): "Test encoding features" @@ -66,14 +67,14 @@ class TestEncoding(unittest.TestCase): self.encoder_function = FlacEncoder self.delta = 0 - def testWebm(self): + def testWebM(self): "Test webm encoding, audio only" from timeside.encoder.webm import WebMEncoder self.encoder_function = WebMEncoder self.test_duration = False # webmmux encoder with streamable=true # does not return a valid duration - def testWebmVideo(self): + def testWebMVideo(self): "Test webm encoding, video" from timeside.encoder.webm import WebMEncoder self.encoder_function = WebMEncoder diff --git a/tests/test_transcoding.py b/tests/test_transcoding.py index cc11432..d345ead 100755 --- a/tests/test_transcoding.py +++ b/tests/test_transcoding.py @@ -22,25 +22,25 @@ class TestTranscodingFromWav(unittest.TestCase): self.test_duration = True self.test_channels = True - def testToWav(self): + def testWav(self): "Test conversion to wav" self.encoder_function = WavEncoder - def testToMp3(self): + def testMp3(self): "Test conversion to mp3" self.encoder_function = Mp3Encoder - def testToOgg(self): + def testOgg(self): "Test conversion to ogg" self.encoder_function = VorbisEncoder - def testToWebM(self): + def testWebM(self): "Test conversion to webm" self.encoder_function = WebMEncoder self.test_duration = False # webmmux encoder with streamable=true # does not return a valid duration - def testToM4a(self): + def testM4a(self): "Test conversion to m4a" self.encoder_function = AacEncoder @@ -89,9 +89,9 @@ class TestTranscodingFromMonoWav(TestTranscodingFromWav): self.source = os.path.join(os.path.dirname(__file__), "samples/sweep_mono.wav") - def testToM4a(self): + def testM4a(self): "Test conversion to m4a" - super(TestTranscodingFromMonoWav, self).testToM4a() + super(TestTranscodingFromMonoWav, self).testM4a() self.test_channels = False # voaacenc bug ? : always encode stereo diff --git a/tests/unit_timeside.py b/tests/unit_timeside.py index 2ec084c..f38f6fd 100644 --- a/tests/unit_timeside.py +++ b/tests/unit_timeside.py @@ -142,14 +142,19 @@ class TestRunner: return result -def runTestModule(*modules): - +def runTestModule(test_modules_list=None, test_prefix=None): suite = unittest.TestSuite() finder = doctest.DocTestFinder(exclude_empty=False) # finder for doctest - - for module in modules: + if test_prefix: + unittest.TestLoader.testMethodPrefix = test_prefix + if not test_modules_list: + test_modules_list = [] + elif not isinstance(test_modules_list, list): + test_modules_list = [test_modules_list] + test_modules_list.append('__main__') + for test in test_modules_list: # Doctest - suite.addTest(doctest.DocTestSuite(module, test_finder=finder)) + suite.addTest(doctest.DocTestSuite(test, test_finder=finder)) # unittest - suite.addTest(unittest.loader.TestLoader().loadTestsFromModule(module)) + suite.addTest(unittest.loader.TestLoader().loadTestsFromModule(test)) TestRunner().run(suite) diff --git a/timeside/decoder/core.py b/timeside/decoder/core.py index 82c9284..1d8d742 100644 --- a/timeside/decoder/core.py +++ b/timeside/decoder/core.py @@ -519,5 +519,5 @@ if __name__ == "__main__": # load corresponding tests from tests import test_decoding, test_array_decoding - runTestModule('__main__', test_decoding, test_array_decoding) + runTestModule([test_decoding, test_array_decoding]) diff --git a/timeside/decoder/utils.py b/timeside/decoder/utils.py index 328883b..5297b5b 100644 --- a/timeside/decoder/utils.py +++ b/timeside/decoder/utils.py @@ -144,5 +144,5 @@ if __name__ == "__main__": # load corresponding tests from tests import test_decoder_utils - runTestModule('__main__', test_decoder_utils) + runTestModule(test_decoder_utils) diff --git a/timeside/encoder/core.py b/timeside/encoder/core.py index 09ce3e3..6ad0eaa 100644 --- a/timeside/encoder/core.py +++ b/timeside/encoder/core.py @@ -146,4 +146,4 @@ if __name__ == "__main__": # Run doctest from __main__ and unittest from test_analyzer_preprocessors from tests import test_encoding, test_transcoding from tests.unit_timeside import runTestModule - runTestModule('__main__', test_encoding, test_transcoding) \ No newline at end of file + runTestModule([test_encoding, test_transcoding]) \ No newline at end of file diff --git a/timeside/encoder/webm.py b/timeside/encoder/webm.py index ba6c9ee..238343e 100644 --- a/timeside/encoder/webm.py +++ b/timeside/encoder/webm.py @@ -34,21 +34,21 @@ class WebMEncoder(GstEncoder): self.video = video @interfacedoc - def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None): - super(WebMEncoder, self).setup(channels, samplerate, blocksize, totalframes) + def setup(self, channels=None, samplerate=None, blocksize=None, + totalframes=None): + super(WebMEncoder, self).setup(channels, samplerate, blocksize, + totalframes) from numpy import ceil framerate = 30 - num_buffers = ceil(self.mediainfo()['duration'] * - framerate).astype(int) + num_buffers = ceil(self.mediainfo()['duration'] * + framerate).astype(int) + self.pipe = '' if self.video: - self.pipe = '''appsrc name=src ! queue ! audioconvert ! vorbisenc quality=0.9 ! queue ! mux. - videotestsrc pattern=black num_buffers=%d ! ffmpegcolorspace ! queue ! vp8enc speed=2 threads=4 quality=9.0 ! queue ! mux. - webmmux streamable=true name=mux - ''' % num_buffers - else: - self.pipe = ''' - appsrc name=src ! queue ! audioconvert ! vorbisenc quality=0.9 ! queue ! - webmmux streamable=true name=mux + self.pipe += '''videotestsrc pattern=black num_buffers=%d ! ffmpegcolorspace ! queue ! vp8enc speed=2 threads=4 quality=9.0 ! queue ! mux. + ''' % num_buffers + self.pipe += ''' + appsrc name=src ! queue ! audioconvert ! vorbisenc quality=0.9 ! queue ! mux. + webmmux streamable=true name=mux ''' if self.filename and self.streaming: self.pipe += ''' ! tee name=t @@ -56,14 +56,13 @@ class WebMEncoder(GstEncoder): t. ! queue ! appsink name=app sync=False ''' % self.filename - elif self.filename : + elif self.filename: self.pipe += '! filesink location=%s async=False sync=False ' % self.filename else: self.pipe += '! queue ! appsink name=app sync=False ' self.start_pipeline(channels, samplerate) - @staticmethod @interfacedoc def id(): @@ -92,3 +91,9 @@ class WebMEncoder(GstEncoder): @interfacedoc def set_metadata(self, metadata): self.metadata = metadata + +if __name__ == "__main__": + # Run doctest from __main__ and unittest from test_analyzer_preprocessors + from tests import test_encoding, test_transcoding + from tests.unit_timeside import runTestModule + runTestModule([test_encoding, test_transcoding], test_prefix='testWebM') \ No newline at end of file -- 2.39.5