source: python/tests/test_note2midi.py @ 7d89e61

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretchpitchshiftsamplertimestretchyinfft+
Last change on this file since 7d89e61 was 7d89e61, checked in by Paul Brossier <piem@piem.org>, 8 years ago

tests/test_{midi2note,note2midi}.py: add header and encoding

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3
4from aubio import note2midi
5import unittest
6
7list_of_known_notes = (
8        ( 'C-1', 0 ),
9        ( 'C#-1', 1 ),
10        ( 'd2', 38 ),
11        ( 'C3', 48 ),
12        ( 'B3', 59 ),
13        ( 'B#3', 60 ),
14        ( 'A4', 69 ),
15        ( 'A#4', 70 ),
16        ( 'Bb4', 70 ),
17        ( u'B♭4', 70 ),
18        ( 'G8', 115 ),
19        ( u'G♯8', 116 ),
20        ( 'G9', 127 ),
21        ( u'G\udd2a2', 45 ),
22        ( u'B\ufffd2', 45 ),
23        ( u'A♮2', 45 ),
24        )
25
26class note2midi_good_values(unittest.TestCase):
27
28    def test_note2midi_known_values(self):
29        " known values are correctly converted "
30        for note, midi in list_of_known_notes:
31            self.assertEqual ( note2midi(note), midi )
32
33class note2midi_wrong_values(unittest.TestCase):
34
35    def test_note2midi_missing_octave(self):
36        " fails when passed only one character"
37        self.assertRaises(ValueError, note2midi, 'C')
38
39    def test_note2midi_wrong_modifier(self):
40        " fails when passed a note with an invalid modifier "
41        self.assertRaises(ValueError, note2midi, 'C.1')
42
43    def test_note2midi_another_wrong_modifier_again(self):
44        " fails when passed a note with a invalid note name "
45        self.assertRaises(ValueError, note2midi, 'CB-3')
46
47    def test_note2midi_wrong_octave(self):
48        " fails when passed a wrong octave number "
49        self.assertRaises(ValueError, note2midi, 'CBc')
50
51    def test_note2midi_out_of_range(self):
52        " fails when passed a out of range note"
53        self.assertRaises(ValueError, note2midi, 'A9')
54
55    def test_note2midi_wrong_data_type(self):
56        " fails when passed a non-string value "
57        self.assertRaises(TypeError, note2midi, 123)
58
59if __name__ == '__main__':
60    unittest.main()
Note: See TracBrowser for help on using the repository browser.