Exemple #1
0
    def reach_wav_size_limit_test(self):
        temp_file = TemporaryFile('w')
        
        def source():
            while True:
                yield numpy.zeros((2**20, 1))

        got_error = False
        try:
            stream_functions.write_wav(source(), temp_file)
        except errors.WavSizeLimitError:
            got_error = True 
        self.assertTrue(got_error)
Exemple #2
0
    def chain_test(self):
        """
        Test that if one generator raises StopIteration up the chain, the sink catches it.
        """
        temp_file = NamedTemporaryFile()
        blocks = []

        def source():
            for i in range(0, 5):
                block = numpy.ones((44100, 2)) * i * 0.1
                blocks.append(block)
                yield block

        def double(source):
            while True:
                yield next(source) * 2

        sink = stream_functions.write_wav(double(source()), temp_file)
        self.assertEqual(sink.infos['frame_rate'], 44100)
        self.assertEqual(sink.infos['channel_count'], 2)

        expected = numpy.concatenate(blocks) * 2
        frame_rate, actual = sp_wavfile.read(temp_file.name)
        actual = actual / float(2**15)
        self.assertEqual(actual.shape, (44100 * 5, 2))
        numpy.testing.assert_array_equal(expected.round(4), actual.round(4))
Exemple #3
0
    def write_incorrect_channel_count_test(self):
        temp_file = NamedTemporaryFile()
        got_error = False

        def source():
            yield numpy.ones((44100, 2)) * 0.1
            yield numpy.ones((44100, 2)) * 0.1
            yield numpy.ones((44100, 1)) * 0.1

        try:
            stream_functions.write_wav(source(), temp_file)
        except ValueError:
            got_error = True

        self.assertTrue(got_error)
        expected = numpy.ones((44100 * 2, 2)) * 0.1
        frame_rate, actual = sp_wavfile.read(temp_file.name)
        actual = actual / float(2**15)
        self.assertEqual(actual.shape, (44100 * 2, 2))
        numpy.testing.assert_array_equal(expected.round(4), actual.round(4))
Exemple #4
0
    def simple_write_test(self):
        temp_file = NamedTemporaryFile()
        blocks = []

        def source():
            for i in range(0, 5):
                block = numpy.ones((44100, 1)) * i * 0.1
                blocks.append(block)
                yield block

        sink = stream_functions.write_wav(source(), temp_file)
        self.assertEqual(sink.infos['frame_rate'], 44100)
        self.assertEqual(sink.infos['channel_count'], 1)

        expected = numpy.concatenate(blocks)
        frame_rate, actual = sp_wavfile.read(temp_file.name)
        actual = numpy.array([actual / float(2**15)]).transpose()
        numpy.testing.assert_array_equal(expected.round(4), actual.round(4))