-from template import aubio_unit_template
-from localaubio import *
+#! /usr/bin/env python
+
+from numpy.testing import TestCase, assert_equal, assert_almost_equal
+from aubio import fvec, digital_filter
import random
buf_size = 2048
nelems = 1000
-class hist_unit(aubio_unit_template):
+class hist_test_case(TestCase):
def setUp(self):
self.o = new_aubio_hist(flow, fhig, nelems, channels)
def test_hist_impulse_under(self):
""" test hist on constant under lower limit """
""" this returns 0 because constant is out of range """
- input = new_fvec(buf_size, channels)
+ vec_in = fvec(buf_size)
constant = flow - 1.
- fvec_write_sample(input,constant,0,0)
+ vec_in[0] = constant
aubio_hist_do_notnull(self.o, input)
self.assertCloseEnough(0., aubio_hist_mean(self.o))
del_fvec(input)
-from template import aubio_unit_template
-from localaubio import *
+from aubio import zero_crossing_rate
+
+#! /usr/bin/env python
+
+from numpy.testing import TestCase
buf_size = 2048
channels = 1
-class zero_crossing_rate_unit(unittest.TestCase):
+class zero_crossing_rate_test_case(TestCase):
def setUp(self):
self.vector = new_fvec(buf_size, channels)
def test_zeroes(self):
""" check zero crossing rate on a buffer of 0. """
- self.assertEqual(0., aubio_zero_crossing_rate(self.vector))
+ self.assertEqual(0., zero_crossing_rate(self.vector))
def test_ones(self):
""" check zero crossing rate on a buffer of 1. """
for index in range(buf_size):
for channel in range(channels):
fvec_write_sample(self.vector, 1., channel, index)
- self.assertEqual(0., aubio_zero_crossing_rate(self.vector))
+ self.assertEqual(0., zero_crossing_rate(self.vector))
def test_impulse(self):
""" check zero crossing rate on a buffer with an impulse """
fvec_write_sample(self.vector, 1., 0, buf_size / 2)
- self.assertEqual(0., aubio_zero_crossing_rate(self.vector))
+ self.assertEqual(0., zero_crossing_rate(self.vector))
def test_negative_impulse(self):
""" check zero crossing rate on a buffer with a negative impulse """
fvec_write_sample(self.vector, -1., 0, buf_size / 2)
- self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector))
+ self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
def test_single(self):
""" check zero crossing rate on single crossing """
fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 1)
fvec_write_sample(self.vector, -1., 0, buf_size / 2)
- self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector))
+ self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
def test_single_with_gap(self):
""" check zero crossing rate on single crossing with a gap"""
fvec_write_sample(self.vector, +1., 0, buf_size / 2 - 2)
fvec_write_sample(self.vector, -1., 0, buf_size / 2)
- self.assertEqual(2./buf_size, aubio_zero_crossing_rate(self.vector))
+ self.assertEqual(2./buf_size, zero_crossing_rate(self.vector))
if __name__ == '__main__':
unittest.main()
+++ /dev/null
-import unittest
-
-class aubiomodule_test_case(unittest.TestCase):
-
- def test_aubio(self):
- """ try importing aubio module """
- import aubio
-
- def test_aubiowrapper(self):
- """ try importing aubio.aubiowrapper module """
- from aubio import aubiowrapper
-
-if __name__ == '__main__':
- unittest.main()
+++ /dev/null
-from template import *
-
-class aubionotes_test_case(program_test_case):
-
- import os.path
- filename = os.path.join('..','..','sounds','woodblock.aiff')
- progname = os.path.join('..','..','examples','aubionotes')
-
- def test_aubionotes(self):
- """ test aubionotes with default parameters """
- self.getOutput()
- # FIXME: useless check
- self.assertEqual(len(self.output.split('\n')), 1)
- self.assertEqual(float(self.output.strip()), 0.017415)
-
- def test_aubionotes_verbose(self):
- """ test aubionotes with -v parameter """
- self.command += " -v "
- self.getOutput()
- # FIXME: loose checking: make sure at least 8 lines are printed
- assert len(self.output) >= 8
-
- def test_aubionotes_devnull(self):
- """ test aubionotes on /dev/null """
- self.filename = "/dev/null"
- # exit status should not be 0
- self.getOutput(expected_status = 256)
- # and there should be an error message
- assert len(self.output) > 0
- # that looks like this
- #output_lines = self.output.split('\n')
- #for line in output_lines:
- # print line
-
-mode_names = ["yinfft", "yin", "fcomb", "mcomb", "schmitt"]
-for name in mode_names:
- exec("class aubionotes_test_case_" + name + "(aubionotes_test_case):\n\
- options = \" -p " + name + " \"")
-
-if __name__ == '__main__': unittest.main()
+++ /dev/null
-
-# add ${src}/python and ${src}/python/aubio/.libs to python path
-# so the script is runnable from a compiled source tree.
-
-try:
- from aubio.aubiowrapper import *
-except ImportError:
- try:
- import os
- import sys
- cur_dir = os.path.dirname(__file__)
- sys.path.append(os.path.join(cur_dir,'..','..','python'))
- # autotools places
- sys.path.append(os.path.join(cur_dir,'..','..','python','aubio'))
- sys.path.append(os.path.join(cur_dir,'..','..','python','aubio','.libs'))
- # waf places
- sys.path.append(os.path.join(cur_dir,'..','..','build', 'default', 'swig'))
- sys.path.append(os.path.join(cur_dir,'..','..','build', 'default', 'python','aubio'))
- from aubiowrapper import *
- except ImportError:
- raise
-else:
- raise ImportError, \
- """
- The aubio module could be imported BEFORE adding the source directory to
- your path. Make sure you NO other version of the python aubio module is
- installed on your system.
- """
-
-from template import *
+++ /dev/null
-#! /usr/bin/python
-
-import unittest
-
-from glob import glob
-def list_of_test_files(path):
- matches = glob(path)
- if not matches: print "WARNING: no matches for %s" % path
- return [i.split('.')[0].replace('/','.') for i in matches]
-
-modules_to_test = []
-modules_to_test += ['localaubio']
-modules_to_test += list_of_test_files('src/*.py')
-modules_to_test += list_of_test_files('src/*/*.py')
-modules_to_test += list_of_test_files('examples/aubio*.py')
-modules_to_test += list_of_test_files('*.py')
-
-if __name__ == '__main__':
- for module in modules_to_test:
- if module != 'run_all_tests': # (not actually needed)
- exec('from %s import *' % module)
- unittest.main()
+++ /dev/null
-import unittest
-from commands import getstatusoutput
-from numpy import array
-
-class aubio_unit_template(unittest.TestCase):
- """ a class derivated from unittest.TestCase """
-
- def assertCloseEnough(self, first, second, places=5, msg=None):
- """Fail if the two objects are unequal as determined by their
- *relative* difference rounded to the given number of decimal places
- (default 7) and comparing to zero.
- """
- if round(first, places) == 0:
- if round(second-first, places) != 0:
- raise self.failureException, \
- (msg or '%r != %r within %r places' % (first, second, places))
- else:
- if round((second-first)/first, places) != 0:
- raise self.failureException, \
- (msg or '%r != %r within %r places' % (first, second, places))
-
-class program_test_case(unittest.TestCase):
-
- filename = "/dev/null"
- progname = "UNDEFINED"
- command = ""
- options = ""
-
- def getOutput(self, expected_status = 0):
- self.command = self.progname + ' -i ' + self.filename + self.command
- self.command += self.options
- [self.status, self.output] = getstatusoutput(self.command)
- if expected_status != -1:
- assert self.status == expected_status, \
- "expected status was %s, got %s\nOutput was:\n%s\n command was %s" % \
- (expected_status, self.status, self.output, self.command)
-
-def array_from_text_file(filename, dtype = 'float'):
- return array([line.split() for line in open(filename).readlines()],
- dtype = dtype)
+++ /dev/null
-import unittest
-
-# this file is just to illustrates and test some of the unittest module
-# functionalities.
-
-class raise_test_case(unittest.TestCase):
- def test_assertEqual(self):
- """ check assertEqual returns AssertionError """
- try:
- self.assertEqual(0.,1.)
- except AssertionError:
- pass
- else:
- fail('expected an AssertionError exception')
-
- def test_assertAlmostEqual(self):
- """ check assertAlmostEqual returns AssertionError """
- try:
- self.assertAlmostEqual(0.,1.)
- except AssertionError:
- pass
- else:
- fail('expected an AssertionError exception')
-
- def test_assertRaises(self):
- """ check assertRaises works as expected """
- self.assertRaises(AssertionError, self.assertEqual, 0.,1.)
- self.assertRaises(AssertionError, self.assertAlmostEqual, 0.,1.,1)
-
-if __name__ == '__main__':
- unittest.main()