From 208336b59c75969bf945e0c2dc048daefba0f5b1 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 5 Mar 2013 02:55:29 -0500 Subject: [PATCH] tests/python/: removed old python tests --- .../hist.py => python/tests/test_hist.py.old | 12 +++--- .../tests/test_zero_crossing_rate.py.old | 21 +++++----- tests/python/aubiomodule.py | 14 ------- tests/python/examples/aubionotes.py | 40 ------------------- tests/python/localaubio.py | 30 -------------- tests/python/run_all_tests | 22 ---------- tests/python/src/__init__.py | 0 tests/python/src/onset/__init__.py | 0 tests/python/src/pitch/__init__.py | 0 tests/python/src/spectral/__init__.py | 0 tests/python/src/temporal/__init__.py | 0 tests/python/src/utils/__init__.py | 0 tests/python/template.py | 40 ------------------- tests/python/unittest_examples.py | 31 -------------- 14 files changed, 19 insertions(+), 191 deletions(-) rename tests/python/src/utils/hist.py => python/tests/test_hist.py.old (90%) rename tests/python/src/temporal/zero_crossing_rate.py => python/tests/test_zero_crossing_rate.py.old (70%) delete mode 100644 tests/python/aubiomodule.py delete mode 100644 tests/python/examples/aubionotes.py delete mode 100644 tests/python/localaubio.py delete mode 100755 tests/python/run_all_tests delete mode 100644 tests/python/src/__init__.py delete mode 100644 tests/python/src/onset/__init__.py delete mode 100644 tests/python/src/pitch/__init__.py delete mode 100644 tests/python/src/spectral/__init__.py delete mode 100644 tests/python/src/temporal/__init__.py delete mode 100644 tests/python/src/utils/__init__.py delete mode 100644 tests/python/template.py delete mode 100644 tests/python/unittest_examples.py diff --git a/tests/python/src/utils/hist.py b/python/tests/test_hist.py.old similarity index 90% rename from tests/python/src/utils/hist.py rename to python/tests/test_hist.py.old index 905235a5..baefa409 100644 --- a/tests/python/src/utils/hist.py +++ b/python/tests/test_hist.py.old @@ -1,5 +1,7 @@ -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 @@ -9,7 +11,7 @@ fhig = float(random.randint(100, 1000) + random.random()) 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) @@ -62,9 +64,9 @@ class hist_unit(aubio_unit_template): 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) diff --git a/tests/python/src/temporal/zero_crossing_rate.py b/python/tests/test_zero_crossing_rate.py.old similarity index 70% rename from tests/python/src/temporal/zero_crossing_rate.py rename to python/tests/test_zero_crossing_rate.py.old index 98ad13c0..1b1d9111 100644 --- a/tests/python/src/temporal/zero_crossing_rate.py +++ b/python/tests/test_zero_crossing_rate.py.old @@ -1,10 +1,13 @@ -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) @@ -18,36 +21,36 @@ class zero_crossing_rate_unit(unittest.TestCase): 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() diff --git a/tests/python/aubiomodule.py b/tests/python/aubiomodule.py deleted file mode 100644 index cc2445c1..00000000 --- a/tests/python/aubiomodule.py +++ /dev/null @@ -1,14 +0,0 @@ -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() diff --git a/tests/python/examples/aubionotes.py b/tests/python/examples/aubionotes.py deleted file mode 100644 index 5d181507..00000000 --- a/tests/python/examples/aubionotes.py +++ /dev/null @@ -1,40 +0,0 @@ -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() diff --git a/tests/python/localaubio.py b/tests/python/localaubio.py deleted file mode 100644 index e09bcac2..00000000 --- a/tests/python/localaubio.py +++ /dev/null @@ -1,30 +0,0 @@ - -# 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 * diff --git a/tests/python/run_all_tests b/tests/python/run_all_tests deleted file mode 100755 index 68caefb2..00000000 --- a/tests/python/run_all_tests +++ /dev/null @@ -1,22 +0,0 @@ -#! /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() diff --git a/tests/python/src/__init__.py b/tests/python/src/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/python/src/onset/__init__.py b/tests/python/src/onset/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/python/src/pitch/__init__.py b/tests/python/src/pitch/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/python/src/spectral/__init__.py b/tests/python/src/spectral/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/python/src/temporal/__init__.py b/tests/python/src/temporal/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/python/src/utils/__init__.py b/tests/python/src/utils/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/python/template.py b/tests/python/template.py deleted file mode 100644 index 687189a6..00000000 --- a/tests/python/template.py +++ /dev/null @@ -1,40 +0,0 @@ -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) diff --git a/tests/python/unittest_examples.py b/tests/python/unittest_examples.py deleted file mode 100644 index 740c7312..00000000 --- a/tests/python/unittest_examples.py +++ /dev/null @@ -1,31 +0,0 @@ -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() -- 2.26.2