test_setup.py 688 字节
Newer Older
L
Luo Tao 已提交
1 2
"""Test Setup."""
import unittest
L
Luo Tao 已提交
3 4
import numpy as np
import os
L
Luo Tao 已提交
5 6 7 8


class TestSetup(unittest.TestCase):
    def test_soundfile(self):
L
Luo Tao 已提交
9 10 11 12 13 14 15 16
        import soundfile as sf
        # floating point data is typically limited to the interval [-1.0, 1.0],
        # but smaller/larger values are supported as well
        data = np.array([[1.75, -1.75], [1.0, -1.0], [0.5, -0.5],
                         [0.25, -0.25]])
        file = 'test.wav'
        sf.write(file, data, 44100, format='WAV', subtype='FLOAT')
        read, fs = sf.read(file)
L
Luo Tao 已提交
17 18
        self.assertTrue(np.all(read == data))
        self.assertEqual(fs, 44100)
L
Luo Tao 已提交
19
        os.remove(file)
L
Luo Tao 已提交
20 21 22 23


if __name__ == '__main__':
    unittest.main()