Changeset 31a5c405


Ignore:
Timestamp:
Feb 23, 2014, 8:39:25 PM (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:
1a121ca
Parents:
1164bcdf
Message:

python/tests/test_source.py: improve tests, add double close and do_multi

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_source.py

    r1164bcdf r31a5c405  
    99path = None
    1010
    11 class aubio_source_test_case(TestCase):
     11class aubio_source_test_case_base(TestCase):
    1212
    1313    def setUp(self):
    1414        if not len(list_of_sounds): self.skipTest('add some sound files in \'python/tests/sounds\'')
     15
     16class aubio_source_test_case(aubio_source_test_case_base):
     17
     18    def test_close_file(self):
     19        samplerate = 0 # use native samplerate
     20        hop_size = 256
     21        for p in list_of_sounds:
     22            f = source(p, samplerate, hop_size)
     23            f.close()
     24
     25    def test_close_file_twice(self):
     26        samplerate = 0 # use native samplerate
     27        hop_size = 256
     28        for p in list_of_sounds:
     29            f = source(p, samplerate, hop_size)
     30            f.close()
     31            f.close()
     32
     33class aubio_source_read_test_case(aubio_source_test_case_base):
    1534
    1635    def read_from_sink(self, f):
     
    6988            self.read_from_sink(f)
    7089
    71     def test_close_file(self):
    72         samplerate = 0 # use native samplerate
    73         hop_size = 256
    74         for p in list_of_sounds:
    75             f = source(p, samplerate, hop_size)
    76             f.close()
     90class aubio_source_readmulti_test_case(aubio_source_read_test_case):
    7791
    78     def test_close_file_twice(self):
    79         samplerate = 0 # use native samplerate
    80         hop_size = 256
    81         for p in list_of_sounds:
    82             f = source(p, samplerate, hop_size)
    83             f.close()
    84             f.close()
     92    def read_from_sink(self, f):
     93        total_frames = 0
     94        while True:
     95            vec, read = f.do_multi()
     96            total_frames += read
     97            if read < f.hop_size: break
     98        print "read", "%.2fs" % (total_frames / float(f.samplerate) ),
     99        print "(", total_frames, "frames", "in",
     100        print f.channels, "channels and",
     101        print total_frames / f.hop_size, "blocks", "at", "%dHz" % f.samplerate, ")",
     102        print "from", f.uri
    85103
    86104if __name__ == '__main__':
Note: See TracChangeset for help on using the changeset viewer.