1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | from numpy.testing import TestCase, run_module_suite |
---|
4 | from numpy.testing import assert_equal, assert_almost_equal |
---|
5 | |
---|
6 | from aubio import slice_source_at_stamps |
---|
7 | from utils import count_samples_in_file, count_samples_in_directory |
---|
8 | |
---|
9 | import tempfile |
---|
10 | import shutil |
---|
11 | |
---|
12 | class aubio_slicing_test_case(TestCase): |
---|
13 | |
---|
14 | def setUp(self): |
---|
15 | self.source_file = 'chocolate_1min.wav' |
---|
16 | self.output_dir = tempfile.mkdtemp(suffix = 'aubio_slicing_test_case') |
---|
17 | |
---|
18 | def test_slice_start_only(self): |
---|
19 | regions_start = [i*1000 for i in range(100)] |
---|
20 | slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) |
---|
21 | |
---|
22 | def test_slice_start_only_no_zero(self): |
---|
23 | regions_start = [i*1000 for i in range(1, 100)] |
---|
24 | slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) |
---|
25 | |
---|
26 | def test_slice_start_beyond_end(self): |
---|
27 | regions_start = [i*1000 for i in range(1, 100)] |
---|
28 | regions_start += [count_samples_in_file(self.source_file)] |
---|
29 | regions_start += [count_samples_in_file(self.source_file) + 1000] |
---|
30 | slice_source_at_stamps(self.source_file, regions_start, output_dir = self.output_dir) |
---|
31 | |
---|
32 | def tearDown(self): |
---|
33 | original_samples = count_samples_in_file(self.source_file) |
---|
34 | written_samples = count_samples_in_directory(self.output_dir) |
---|
35 | assert_equal(original_samples, written_samples, |
---|
36 | "number samples written different from number of original samples") |
---|
37 | shutil.rmtree(self.output_dir) |
---|
38 | |
---|
39 | if __name__ == '__main__': |
---|
40 | from unittest import main |
---|
41 | main() |
---|