source: python/tests/test_midi2note.py @ 26bd5e0

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 26bd5e0 was 7fd92ca, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] use run_module_suite so tests can run when pytest is not installed

  • Property mode set to 100755
File size: 1.3 KB
RevLine 
[7d89e61]1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
[9ead7a9]3
4from aubio import midi2note
[d4fae34]5from _tools import parametrize, assert_raises
[9ead7a9]6
7list_of_known_midis = (
8        ( 0, 'C-1' ),
9        ( 1, 'C#-1' ),
10        ( 38, 'D2' ),
11        ( 48, 'C3' ),
12        ( 59, 'B3' ),
13        ( 60, 'C4' ),
14        ( 127, 'G9' ),
15        )
16
[8607a74]17class Test_midi2note_good_values(object):
[9ead7a9]18
[4c1eff4]19    @parametrize('midi, note', list_of_known_midis)
[d554321]20    def test_midi2note_known_values(self, midi, note):
[9ead7a9]21        " known values are correctly converted "
[4c1eff4]22        assert midi2note(midi) == (note)
[9ead7a9]23
[8607a74]24class Test_midi2note_wrong_values(object):
[9ead7a9]25
26    def test_midi2note_negative_value(self):
27        " fails when passed a negative value "
[4c1eff4]28        assert_raises(ValueError, midi2note, -2)
[9ead7a9]29
[0b6d23d]30    def test_midi2note_large(self):
[9ead7a9]31        " fails when passed a value greater than 127 "
[4c1eff4]32        assert_raises(ValueError, midi2note, 128)
[9ead7a9]33
34    def test_midi2note_floating_value(self):
35        " fails when passed a floating point "
[4c1eff4]36        assert_raises(TypeError, midi2note, 69.2)
[9ead7a9]37
38    def test_midi2note_character_value(self):
39        " fails when passed a value that can not be transformed to integer "
[4c1eff4]40        assert_raises(TypeError, midi2note, "a")
[9ead7a9]41
42if __name__ == '__main__':
[7fd92ca]43    from _tools import run_module_suite
44    run_module_suite()
Note: See TracBrowser for help on using the repository browser.