Changeset aee840b for python/tests


Ignore:
Timestamp:
Jan 12, 2014, 3:33:07 AM (11 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
6f27719
Parents:
8203ae5
Message:

python/lib/aubio/slicing.py: error checking, add more tests, use get_default_sound

Location:
python/tests
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_slicing.py

    r8203ae5 raee840b  
    66from aubio import slice_source_at_stamps
    77from utils import count_samples_in_file, count_samples_in_directory
     8from utils import get_default_test_sound
    89
    910import tempfile
     
    1314
    1415    def setUp(self):
    15         self.source_file = 'chocolate_1min.wav'
     16        self.source_file = get_default_test_sound(self)
    1617        self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
    1718
     
    3738        shutil.rmtree(self.output_dir)
    3839
     40class aubio_slicing_wrong_starts_test_case(TestCase):
     41
     42    def setUp(self):
     43        self.source_file = get_default_test_sound(self)
     44        self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
     45
     46    def test_slice_start_empty(self):
     47        regions_start = []
     48        self.assertRaises(ValueError,
     49                slice_source_at_stamps,
     50                self.source_file, regions_start, output_dir = self.output_dir)
     51
     52    def test_slice_start_none(self):
     53        regions_start = None
     54        self.assertRaises(ValueError,
     55                slice_source_at_stamps,
     56                self.source_file, regions_start, output_dir = self.output_dir)
     57
     58    def tearDown(self):
     59        shutil.rmtree(self.output_dir)
     60
     61class aubio_slicing_wrong_ends_test_case(TestCase):
     62
     63    def setUp(self):
     64        self.source_file = get_default_test_sound(self)
     65        self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case')
     66
     67    def test_slice_wrong_ends(self):
     68        regions_start = [i*1000 for i in range(1, 100)]
     69        regions_end = []
     70        self.assertRaises (ValueError,
     71            slice_source_at_stamps, self.source_file, regions_start, regions_end,
     72                output_dir = self.output_dir)
     73
     74    def test_slice_no_ends(self):
     75        regions_start = [i*1000 for i in range(1, 100)]
     76        regions_end = None
     77        slice_source_at_stamps (self.source_file, regions_start, regions_end,
     78                output_dir = self.output_dir)
     79        original_samples = count_samples_in_file(self.source_file)
     80        written_samples = count_samples_in_directory(self.output_dir)
     81        assert_equal(original_samples, written_samples,
     82            "number samples written different from number of original samples")
     83
     84    def tearDown(self):
     85        shutil.rmtree(self.output_dir)
     86
    3987if __name__ == '__main__':
    4088    from unittest import main
  • python/tests/utils.py

    r8203ae5 raee840b  
    1212    datadir = os.path.join(os.path.dirname(__file__), rel_dir)
    1313    return glob.glob(os.path.join(datadir,'*.*'))
     14
     15def get_default_test_sound(TestCase, rel_dir = 'sounds'):
     16    all_sounds = list_all_sounds(rel_dir)
     17    if len(all_sounds) == 0:
     18        TestCase.skipTest("please add some sounds in \'python/tests/sounds\'")
     19    else:
     20        return all_sounds[0]
    1421
    1522def array_from_yaml_file(filename):
Note: See TracChangeset for help on using the changeset viewer.