def test_algorithm_availability(self): """ Tests if the flag for the SINC algorithm is only available, when the scikits.samplerate library is available as well. """ if common.lib_available("scikits.samplerate"): self.assertIn("SINC", vars(sumpf.modules.ResampleSignal)) else: self.assertNotIn("SINC", vars(sumpf.modules.ResampleSignal))
def test_connectors(self): """ Tests if the connectors are properly decorated. """ if common.lib_available("numpy"): aur = sumpf.modules.ThieleSmallParameterAuralizationLinear() self.assertEqual(aur.SetThieleSmallParameters.GetType(), sumpf.ThieleSmallParameters) self.assertEqual(aur.SetVoltage.GetType(), sumpf.Signal) self.assertEqual(aur.SetListenerDistance.GetType(), float) self.assertEqual(aur.SetMediumDensity.GetType(), float) self.assertEqual(aur.GetExcursion.GetType(), sumpf.Signal) self.assertEqual(aur.GetVelocity.GetType(), sumpf.Signal) self.assertEqual(aur.GetAcceleration.GetType(), sumpf.Signal) self.assertEqual(aur.GetCurrent.GetType(), sumpf.Signal) self.assertEqual(aur.GetSoundPressure.GetType(), sumpf.Signal) for getter in [aur.GetExcursion, aur.GetVelocity, aur.GetAcceleration, aur.GetCurrent, aur.GetSoundPressure]: common.test_connection_observers(testcase=self, inputs=[aur.SetThieleSmallParameters, aur.SetVoltage, aur.SetListenerDistance, aur.SetMediumDensity], noinputs=[], output=getter) aur = sumpf.modules.ThieleSmallParameterAuralizationNonlinear() self.assertEqual(aur.SetThieleSmallParameters.GetType(), sumpf.ThieleSmallParameters) self.assertEqual(aur.SetVoltage.GetType(), sumpf.Signal) self.assertEqual(aur.SetListenerDistance.GetType(), float) self.assertEqual(aur.SetMediumDensity.GetType(), float) self.assertEqual(aur.SetWarpFrequency.GetType(), float) self.assertEqual(aur.SetRegularization.GetType(), float) self.assertEqual(aur.SetSaveSamples.GetType(), bool) self.assertEqual(aur.SetUseCython.GetType(), bool) self.assertEqual(aur.GetExcursion.GetType(), sumpf.Signal) self.assertEqual(aur.GetVelocity.GetType(), sumpf.Signal) self.assertEqual(aur.GetAcceleration.GetType(), sumpf.Signal) self.assertEqual(aur.GetCurrent.GetType(), sumpf.Signal) self.assertEqual(aur.GetSoundPressure.GetType(), sumpf.Signal) for getter in [aur.GetExcursion, aur.GetVelocity, aur.GetAcceleration, aur.GetCurrent, aur.GetSoundPressure]: common.test_connection_observers(testcase=self, inputs=[aur.SetThieleSmallParameters, aur.SetVoltage, aur.SetListenerDistance, aur.SetMediumDensity, aur.SetWarpFrequency, aur.SetRegularization], noinputs=[aur.SetSaveSamples, aur.SetUseCython, aur.ResetSavedSamples], output=getter)
def test_sine(self): """ Tests the derivative of a sine wave Signal. """ frequency = 1.9 samplingrate = 48000 length = 5 * samplingrate sin = sumpf.modules.SineWaveGenerator(frequency=frequency, phase=0.0, samplingrate=samplingrate, length=length) cos = sumpf.modules.SineWaveGenerator(frequency=frequency, phase=math.pi / 2.0, samplingrate=samplingrate, length=length) drv = sumpf.modules.DifferentiateSignal() places = 2 if common.lib_available("numpy"): drv.SetFunction(lambda sequence: sumpf.helper.differentiate_spline(sequence=sequence, degree=2)) places = 6 self.assertEqual(drv.GetOutput(), sumpf.Signal()) drv.SetInput(sin.GetSignal()) common.compare_signals_almost_equal(self, drv.GetOutput(), cos.GetSignal() * (2.0 * math.pi * frequency), places)
# GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import unittest import re import os import sumpf import _common as common from .process import MissingLibProcess @unittest.skipUnless(sumpf.config.get("run_long_tests"), "Long tests are skipped") @unittest.skipUnless(common.lib_available("numpy"), "These tests require the library 'numpy' to be available.") class TestMissingLibs(unittest.TestCase): """ Tests if SuMPF still works, if the external libs are missing and if it limits its functionality accordingly, by hiding classes that rely on these libs. """ def test_signal_formats(self): """ Tests if the correct signal formats are unavailable when audiolab and oct2py are missing. """ process = MissingLibProcess(libnames=["soundfile", "scikits", "oct2py"], function=MissingLibProcess.FILE_FORMATS, formats=["AIFF_FLOAT", "AIFF_INT", "FLAC", "WAV_DOUBLE", "WAV_FLOAT", "WAV_INT", "ITA_AUDIO", "MATLAB"], data_type="Signal") process.start()