From: Paul Brossier Date: Thu, 17 Jan 2013 15:53:20 +0000 (-0600) Subject: tests/testdecoding.py: improve tests to make sure input specs are preserved X-Git-Tag: 0.4.3~2^2~4 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=e28e66b3df666e244f0994fcaea2cfbdcd56d73b;p=timeside.git tests/testdecoding.py: improve tests to make sure input specs are preserved --- diff --git a/tests/testdecoding.py b/tests/testdecoding.py index a8b64f8..6e0c175 100644 --- a/tests/testdecoding.py +++ b/tests/testdecoding.py @@ -13,18 +13,30 @@ class TestDecoding(TestCase): "Test wav decoding" self.source = os.path.join (os.path.dirname(__file__), "samples/sweep.wav") + self.expected_channels = 2 + self.expected_samplerate = 44100 + def testFlac(self): "Test flac decoding" self.source = os.path.join (os.path.dirname(__file__), "samples/sweep.flac") + self.expected_channels = 2 + self.expected_samplerate = 44100 + def testOgg(self): "Test ogg decoding" self.source = os.path.join (os.path.dirname(__file__), "samples/sweep.ogg") + self.expected_channels = 2 + self.expected_samplerate = 44100 + def testMp3(self): "Test mp3 decoding" self.source = os.path.join (os.path.dirname(__file__), "samples/sweep.mp3") + self.expected_channels = 2 + self.expected_samplerate = 44100 + def tearDown(self): decoder = FileDecoder(self.source) @@ -47,6 +59,23 @@ class TestDecoding(TestCase): print "input_duration:", decoder.input_duration print "input_totalframes:", decoder.input_totalframes + if self.channels: + # when specified, check that the channels are the ones requested + self.assertEquals(self.channels, decoder.output_channels) + else: + # otherwise check that the channels are preserved, if not specified + self.assertEquals(decoder.input_channels, decoder.output_channels) + # and if we know the expected channels, check the output match + if self.expected_channels: + self.assertEquals(self.expected_channels, decoder.output_channels) + # do the same with the sampling rate + if self.samplerate: + self.assertEquals(self.samplerate, decoder.output_samplerate) + else: + self.assertEquals(decoder.input_samplerate, decoder.output_samplerate) + if self.expected_samplerate: + self.assertEquals(self.expected_samplerate, decoder.output_samplerate) + # FIXME compute actual number of frames from file if ratio == 1: if os.path.splitext(self.source)[-1].lower() == '.mp3':