[ci] add pip install to readthedocs.yaml
[aubio.git] / python / tests / test_midi2note.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from aubio import midi2note
5 from _tools import parametrize, assert_raises
6
7 list_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
17 class Test_midi2note_good_values(object):
18
19     @parametrize('midi, note', list_of_known_midis)
20     def test_midi2note_known_values(self, midi, note):
21         " known values are correctly converted "
22         assert midi2note(midi) == (note)
23
24 class Test_midi2note_wrong_values(object):
25
26     def test_midi2note_negative_value(self):
27         " fails when passed a negative value "
28         assert_raises(ValueError, midi2note, -2)
29
30     def test_midi2note_large(self):
31         " fails when passed a value greater than 127 "
32         assert_raises(ValueError, midi2note, 128)
33
34     def test_midi2note_floating_value(self):
35         " fails when passed a floating point "
36         assert_raises(TypeError, midi2note, 69.2)
37
38     def test_midi2note_character_value(self):
39         " fails when passed a value that can not be transformed to integer "
40         assert_raises(TypeError, midi2note, "a")
41
42 if __name__ == '__main__':
43     from _tools import run_module_suite
44     run_module_suite()