added examples tests
authorPaul Brossier <piem@piem.org>
Wed, 31 Oct 2007 11:26:02 +0000 (12:26 +0100)
committerPaul Brossier <piem@piem.org>
Wed, 31 Oct 2007 11:26:02 +0000 (12:26 +0100)
tests/python/examples/README [new file with mode: 0644]
tests/python/examples/__init__.py [new file with mode: 0644]
tests/python/examples/aubionotes.py [new file with mode: 0644]
tests/python/examples/aubioonset.py [new file with mode: 0644]
tests/python/examples/template.py [new file with mode: 0644]
tests/python/run_all_tests

diff --git a/tests/python/examples/README b/tests/python/examples/README
new file mode 100644 (file)
index 0000000..684e1a2
--- /dev/null
@@ -0,0 +1 @@
+Python unit tests checking the output of the programs in aubio/examples/
diff --git a/tests/python/examples/__init__.py b/tests/python/examples/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/python/examples/aubionotes.py b/tests/python/examples/aubionotes.py
new file mode 100644 (file)
index 0000000..9fdf4a6
--- /dev/null
@@ -0,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()
diff --git a/tests/python/examples/aubioonset.py b/tests/python/examples/aubioonset.py
new file mode 100644 (file)
index 0000000..1b0f4ab
--- /dev/null
@@ -0,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()
diff --git a/tests/python/examples/template.py b/tests/python/examples/template.py
new file mode 100644 (file)
index 0000000..65f3f20
--- /dev/null
@@ -0,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)
index bcb4afe6ade8c586edbe655157189fdff62fe62f..e2f8065fcfc21386fc999b8a988de3595f6ffbb5 100755 (executable)
@@ -11,10 +11,14 @@ sys.path.append(os.path.join(cur_dir,'..','..','python','aubio','.libs'))
 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()