ref: 031b1f90e2335bfe846b7c60be17ae9492d25f11
parent: f14d3235c1cb865f1d5ab16065dbff6152e6480b
author: Paul Brossier <piem@piem.org>
date: Wed Oct 31 08:26:02 EDT 2007
added examples tests
--- /dev/null
+++ b/tests/python/examples/README
@@ -1,0 +1,1 @@
+Python unit tests checking the output of the programs in aubio/examples/
--- /dev/null
+++ b/tests/python/examples/aubionotes.py
@@ -1,0 +1,36 @@
+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','aubioonset')
+
+ def test_aubionotes(self):
+ """ test aubionotes with default parameters """
+ self.getOutput()
+ # FIXME: useless check
+ assert len(self.output) >= 0
+
+ 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 = -1)
+ assert self.status != 0
+ # and there should be an error message
+ assert len(self.output) > 0
+ # that looks like this
+ output_lines = self.output.split('\n')
+ assert output_lines[0] == "Unable to open input file /dev/null."
+ #assert output_lines[1] == "Supported file format but file is malformed."
+ assert output_lines[2] == "Could not open input file /dev/null."
+
+if __name__ == '__main__': unittest.main()
--- /dev/null
+++ b/tests/python/examples/aubioonset.py
@@ -1,0 +1,58 @@
+from template import *
+
+class aubioonset_test_case(program_test_case):
+
+ import os.path
+ filename = os.path.join('..','..','sounds','woodblock.aiff')
+ progname = os.path.join('..','..','examples','aubioonset')
+
+ def test_aubioonset(self):
+ """ test aubioonset with default parameters """
+ self.getOutput()
+
+ def test_aubioonset_with_inf_silence(self):
+ """ test aubioonset with -s 0 """
+ self.command += " -s 0"
+ self.getOutput()
+ assert len(self.output) == 0, self.output
+
+ def test_aubioonset_with_no_silence(self):
+ """ test aubioonset with -s -100 """
+ self.command += " -s -100 "
+ self.getOutput()
+ # only one onset in woodblock.aiff
+ assert len(self.output.split('\n')) == 1
+ assert len(str(self.output)) != 0, "no output produced with command:\n" + self.command
+ # onset should be at 0.00000
+ assert float(self.output.strip()) == 0.
+
+class aubioonset_test_case_energy(aubioonset_test_case):
+ def setUp(self, options = " -O energy "):
+ aubioonset_test_case.setUp(self, options = options)
+
+class aubioonset_test_case_specdiff(aubioonset_test_case):
+ def setUp(self, options = " -O specdiff "):
+ aubioonset_test_case.setUp(self, options = options)
+
+class aubioonset_test_case_hfc(aubioonset_test_case):
+ def setUp(self, options = " -O hfc "):
+ aubioonset_test_case.setUp(self, options = options)
+
+class aubioonset_test_case_complex(aubioonset_test_case):
+ def setUp(self, options = " -O complex "):
+ aubioonset_test_case.setUp(self, options = options)
+
+class aubioonset_test_case_phase(aubioonset_test_case):
+ def setUp(self, options = " -O phase "):
+ aubioonset_test_case.setUp(self, options = options)
+
+class aubioonset_test_case_kl(aubioonset_test_case):
+ def setUp(self, options = " -O kl "):
+ aubioonset_test_case.setUp(self, options = options)
+
+class aubioonset_test_case_mkl(aubioonset_test_case):
+ def setUp(self, options = " -O mkl "):
+ aubioonset_test_case.setUp(self, options = options)
+
+if __name__ == '__main__':
+ unittest.main()
--- /dev/null
+++ b/tests/python/examples/template.py
@@ -1,0 +1,20 @@
+import unittest
+from commands import getstatusoutput
+
+class program_test_case(unittest.TestCase):
+
+ filename = "/dev/null"
+ progname = "UNDEFINED"
+ command = ""
+
+ def setUp(self, options = ""):
+ self.options = 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" % \
+ (expected_status, self.status, self.output)
--- a/tests/python/run_all_tests
+++ b/tests/python/run_all_tests
@@ -11,10 +11,14 @@
import unittest
from glob import glob
-modules_to_test = [i.split('.')[0] for i in glob('*.py')]
+def list_of_test_files(path):
+ return [i.split('.')[0].replace('/','.') for i in glob(path)]
+modules_to_test = list_of_test_files('*.py')
+modules_to_test += list_of_test_files('examples/aubio*.py')
+
if __name__ == '__main__':
for module in modules_to_test:
- if module != 'all_tests': # (not actually needed)
+ if module != 'run_all_tests': # (not actually needed)
exec('from %s import *' % module)
unittest.main()