]> git.parisson.com Git - timeside.git/commitdiff
tests/testdecoding.py: improve tests to make sure input specs are preserved
authorPaul Brossier <piem@piem.org>
Thu, 17 Jan 2013 15:53:20 +0000 (09:53 -0600)
committerPaul Brossier <piem@piem.org>
Thu, 17 Jan 2013 15:53:20 +0000 (09:53 -0600)
tests/testdecoding.py

index a8b64f811f8cc4315aacabff63ee5985d1f5c998..6e0c175899bef1084f2b9c5c97639238a9795ccc 100644 (file)
@@ -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':