diff options
author | John Glover <j@johnglover.net> | 2012-06-28 17:25:38 +0100 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-06-28 17:25:38 +0100 |
commit | 974a493e6c6e2563de08952cb16792e691396afa (patch) | |
tree | 0e2433a7eebbd8246dbf653e405c7d0622e5b94d | |
parent | 1a4d16e36a534f699bba9a42ff4f9d23cda1628d (diff) | |
download | simpl-974a493e6c6e2563de08952cb16792e691396afa.tar.gz simpl-974a493e6c6e2563de08952cb16792e691396afa.tar.bz2 simpl-974a493e6c6e2563de08952cb16792e691396afa.zip |
[tests] Remove old SMS test file.
-rw-r--r-- | tests/test_sms_old.py | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/tests/test_sms_old.py b/tests/test_sms_old.py deleted file mode 100644 index b28cd9f..0000000 --- a/tests/test_sms_old.py +++ /dev/null @@ -1,110 +0,0 @@ -import unittest -from pysms import SMS_Header, SMS_Data, SMS_SndHeader, SMS_AnalParams, \ - sms_openSF, sms_errorString, sms_getSound, \ - sms_fillHeader, sms_init, sms_initAnalysis, sms_allocFrameH, \ - sms_freeFrame, sms_freeAnalysis, sms_free -from scipy import zeros, sin, pi, asarray, int16 -from scipy.io.wavfile import read, write -import os -import random -from pylab import plot, show - -TEST_AUDIO_FILE = "Tests.wav" - -# Create a test audio file (1 second of a sine wave at 220 Hz) -test_audio = zeros(44100) -for sample_number in range(test_audio.size): - test_audio[sample_number] = sin(2 * pi * 220 * sample_number / 44100.0) -# convert to int values -test_audio *= 32767 -test_audio = asarray(test_audio, int16) - -def create_test_audio_file(): - "Create a test audio file in the current directory" - write(TEST_AUDIO_FILE, 44100, test_audio) - -def delete_test_audio_file(): - "Delete the test audio file created by the function create_test_audio_file" - os.remove(TEST_AUDIO_FILE) - -class TestSoundIO(unittest.TestCase): - def setUp(self): - self.snd_header = SMS_SndHeader() - - def test_sms_openSF_file_exists(self): - "sms_openSF returns True when trying to open an existing file" - create_test_audio_file() - self.assert_(sms_openSF(TEST_AUDIO_FILE, self.snd_header) == 0) - delete_test_audio_file() - - def test_sms_openSF_file_missing(self): - "sms_openSF returns False when trying to open a file that doesn't exist" - file_path = "" - max_file_names = 1000 - count = 0 - class MaxFilesReached(Exception): pass - # create a path to a non-existent file - while True: - file_path = str(random.randint(0, max_file_names)) + ".wav" - if not os.path.isfile(file_path): - break - if count > max_file_names: - raise MaxFilesReached - count += 1 - # call sms_openSF, should return an error - self.assertRaises(IndexError, sms_openSF, file_path, self.snd_header) - - def test_sms_getSound(self): - "sms_getSound" - create_test_audio_file() - self.assert_(sms_openSF(TEST_AUDIO_FILE, self.snd_header) == 0) - frame_size = 512 - frame = zeros(frame_size).astype('float32') - self.assert_(sms_getSound(self.snd_header, frame, 0) == 0) - # test that values read in are the same as those written (allowing for some rounding errors) - class SampleMismatch(Exception): pass - for sample_number in range(frame_size): - if abs((test_audio[sample_number] / 32768.0) - frame[sample_number] > 0.000001): - raise SampleMismatch - delete_test_audio_file() - -class TestInit(unittest.TestCase): - def setUp(self): - self.snd_header = SMS_SndHeader() - self.sms_header = SMS_Header() - self.data = SMS_Data() - self.analysis_params = SMS_AnalParams() - - def tearDown(self): - sms_freeFrame(self.data) - - def test_sms_fillHeader(self): - "sms_fillHeader copies data from an SMS_AnalParams to an SMS_Header" - data_fields = ["nFrames", "iFormat", "iFrameRate", "iStochasticType", \ - "nTracks", "iSamplingRate", "nStochasticCoeff"] - sms_fillHeader(self.sms_header, self.analysis_params, "") - for field in data_fields: - self.assert_(eval("self.sms_header."+field) == eval("self.analysis_params."+field)) - - def test_sms_init(self): - "sms_init" - self.assert_(sms_init() == 0) - - def test_sms_initAnalysis(self): - "sms_initAnalysis" - create_test_audio_file() - if(sms_openSF(TEST_AUDIO_FILE, self.snd_header)): - raise NameError("error opening sound file: " + sms_errorString()) - self.assert_(sms_initAnalysis(self.analysis_params, self.snd_header) == 0) - delete_test_audio_file() - - def test_sms_allocFrameH(self): - "sms_allocFrameH" - create_test_audio_file() - if(sms_openSF(TEST_AUDIO_FILE, self.snd_header)): - raise NameError("error opening sound file: " + sms_errorString()) - self.assert_(sms_allocFrameH(self.sms_header, self.data) == 0) - delete_test_audio_file() - -if __name__ == '__main__': - unittest.main() |