Showing the changes to python/tests (1 of 2 files). Show all
Unified · Split
| @@ -32,7 +32,7 @@ class aubio_source_test_case(aubio_source_test_case_base): · 31 unmodified lines | ||
| 32 | 32 | |
| 33 | 33 | class aubio_source_read_test_case(aubio_source_test_case_base): |
| 34 | 34 | |
| 35 | − def read_from_sink(self, f): | |
| 35 | + def read_from_source(self, f): | |
| 36 | 36 | total_frames = 0 |
| 37 | 37 | while True: |
| 38 | 38 | vec, read = f() |
| @@ -42,25 +42,26 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 3 unmodified lines | ||
| 42 | 42 | print "(", total_frames, "frames", "in", |
| 43 | 43 | print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")", |
| 44 | 44 | print "from", f.uri |
| 45 | + return total_frames | |
| 45 | 46 | |
| 46 | 47 | def test_samplerate_hopsize(self): |
| 47 | 48 | for p in list_of_sounds: |
| 48 | 49 | for samplerate, hop_size in zip([0, 44100, 8000, 32000], [ 512, 512, 64, 256]): |
| 49 | 50 | f = source(p, samplerate, hop_size) |
| 50 | 51 | assert f.samplerate != 0 |
| 51 | − self.read_from_sink(f) | |
| 52 | + self.read_from_source(f) | |
| 52 | 53 | |
| 53 | 54 | def test_samplerate_none(self): |
| 54 | 55 | for p in list_of_sounds: |
| 55 | 56 | f = source(p) |
| 56 | 57 | assert f.samplerate != 0 |
| 57 | − self.read_from_sink(f) | |
| 58 | + self.read_from_source(f) | |
| 58 | 59 | |
| 59 | 60 | def test_samplerate_0(self): |
| 60 | 61 | for p in list_of_sounds: |
| 61 | 62 | f = source(p, 0) |
| 62 | 63 | assert f.samplerate != 0 |
| 63 | − self.read_from_sink(f) | |
| 64 | + self.read_from_source(f) | |
| 64 | 65 | |
| 65 | 66 | def test_wrong_samplerate(self): |
| 66 | 67 | for p in list_of_sounds: |
| @@ -85,11 +86,23 @@ class aubio_source_read_test_case(aubio_source_test_case_base): · 18 unmodified lines | ||
| 85 | 86 | f = source(p, 0, 0) |
| 86 | 87 | assert f.samplerate != 0 |
| 87 | 88 | assert f.hop_size != 0 |
| 88 | − self.read_from_sink(f) | |
| 89 | + self.read_from_source(f) | |
| 90 | + | |
| 91 | + def test_seek_to_half(self): | |
| 92 | + from random import randint | |
| 93 | + for p in list_of_sounds: | |
| 94 | + f = source(p, 0, 0) | |
| 95 | + assert f.samplerate != 0 | |
| 96 | + assert f.hop_size != 0 | |
| 97 | + a = self.read_from_source(f) | |
| 98 | + c = randint(0, a) | |
| 99 | + f.seek(c) | |
| 100 | + b = self.read_from_source(f) | |
| 101 | + assert a == b + c | |
| 89 | 102 | |
| 90 | 103 | class aubio_source_readmulti_test_case(aubio_source_read_test_case): |
| 91 | 104 | |
| 92 | − def read_from_sink(self, f): | |
| 105 | + def read_from_source(self, f): | |
| 93 | 106 | total_frames = 0 |
| 94 | 107 | while True: |
| 95 | 108 | vec, read = f.do_multi() |
| @@ -100,6 +113,7 @@ class aubio_source_readmulti_test_case(aubio_source_read_test_case): · 4 unmodified lines | ||
| 100 | 113 | print f.channels, "channels and", |
| 101 | 114 | print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")", |
| 102 | 115 | print "from", f.uri |
| 116 | + return total_frames | |
| 103 | 117 | |
| 104 | 118 | if __name__ == '__main__': |
| 105 | 119 | from unittest import main |