ref: aee840b6e69427658b1c80540c08da514e92836c
parent: 8203ae591b65235eb7712944b9baf142ab25a7f4
author: Paul Brossier <piem@piem.org>
date: Sat Jan 11 17:33:07 EST 2014
python/lib/aubio/slicing.py: error checking, add more tests, use get_default_sound
--- a/python/lib/aubio/slicing.py
+++ b/python/lib/aubio/slicing.py
@@ -6,6 +6,12 @@
samplerate = 0,
hopsize = 256):
+ if timestamps == None or len(timestamps) == 0:
+ raise ValueError ("no timestamps given")
+
+ if timestamps_end != None and len(timestamps_end) != len(timestamps):
+ raise ValueError ("len(timestamps_end) != len(timestamps)")
+
source_base_name, source_ext = os.path.splitext(os.path.basename(source_file))
if output_dir != None:
if not os.path.isdir(output_dir):
binary files /dev/null b/python/tests/sounds/chocolate_1min.wav differ
--- a/python/tests/test_slicing.py
+++ b/python/tests/test_slicing.py
@@ -5,6 +5,7 @@
from aubio import slice_source_at_stamps
from utils import count_samples_in_file, count_samples_in_directory
+from utils import get_default_test_sound
import tempfile
import shutil
@@ -12,7 +13,7 @@
class aubio_slicing_test_case(TestCase):
def setUp(self):
- self.source_file = 'chocolate_1min.wav'
+ self.source_file = get_default_test_sound(self)
self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
def test_slice_start_only(self):
@@ -34,6 +35,53 @@
written_samples = count_samples_in_directory(self.output_dir)
assert_equal(original_samples, written_samples,
"number samples written different from number of original samples")
+ shutil.rmtree(self.output_dir)
+
+class aubio_slicing_wrong_starts_test_case(TestCase):
+
+ def setUp(self):
+ self.source_file = get_default_test_sound(self)
+ self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
+
+ def test_slice_start_empty(self):
+ regions_start = []
+ self.assertRaises(ValueError,
+ slice_source_at_stamps,
+ self.source_file, regions_start, output_dir = self.output_dir)
+
+ def test_slice_start_none(self):
+ regions_start = None
+ self.assertRaises(ValueError,
+ slice_source_at_stamps,
+ self.source_file, regions_start, output_dir = self.output_dir)
+
+ def tearDown(self):
+ shutil.rmtree(self.output_dir)
+
+class aubio_slicing_wrong_ends_test_case(TestCase):
+
+ def setUp(self):
+ self.source_file = get_default_test_sound(self)
+ self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
+
+ def test_slice_wrong_ends(self):
+ regions_start = [i*1000 for i in range(1, 100)]
+ regions_end = []
+ self.assertRaises (ValueError,
+ slice_source_at_stamps, self.source_file, regions_start, regions_end,
+ output_dir = self.output_dir)
+
+ def test_slice_no_ends(self):
+ regions_start = [i*1000 for i in range(1, 100)]
+ regions_end = None
+ slice_source_at_stamps (self.source_file, regions_start, regions_end,
+ output_dir = self.output_dir)
+ original_samples = count_samples_in_file(self.source_file)
+ written_samples = count_samples_in_directory(self.output_dir)
+ assert_equal(original_samples, written_samples,
+ "number samples written different from number of original samples")
+
+ def tearDown(self):
shutil.rmtree(self.output_dir)
if __name__ == '__main__':
--- a/python/tests/utils.py
+++ b/python/tests/utils.py
@@ -12,6 +12,13 @@
datadir = os.path.join(os.path.dirname(__file__), rel_dir)
return glob.glob(os.path.join(datadir,'*.*'))
+def get_default_test_sound(TestCase, rel_dir = 'sounds'):
+ all_sounds = list_all_sounds(rel_dir)
+ if len(all_sounds) == 0:
+ TestCase.skipTest("please add some sounds in \'python/tests/sounds\'")
+ else:
+ return all_sounds[0]
+
def array_from_yaml_file(filename):
import yaml
f = open(filename)