source: python/tests/test_note2midi.py @ 650cae3

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 650cae3 was 7d89e61, checked in by Paul Brossier <piem@piem.org>, 12 years ago

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

  • Property mode set to 100755
File size: 1.8 KB
RevLine 
[7d89e61]1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
[33102ab]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 ),
[f552e9e]16        ( 'Bb4', 70 ),
17        ( u'B♭4', 70 ),
[33102ab]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
[7d89e61]26class note2midi_good_values(unittest.TestCase):
[33102ab]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
[7d89e61]33class note2midi_wrong_values(unittest.TestCase):
[33102ab]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):
[f552e9e]40        " fails when passed a note with an invalid modifier "
[33102ab]41        self.assertRaises(ValueError, note2midi, 'C.1')
42
[f552e9e]43    def test_note2midi_another_wrong_modifier_again(self):
44        " fails when passed a note with a invalid note name "
[33102ab]45        self.assertRaises(ValueError, note2midi, 'CB-3')
46
47    def test_note2midi_wrong_octave(self):
[f552e9e]48        " fails when passed a wrong octave number "
[33102ab]49        self.assertRaises(ValueError, note2midi, 'CBc')
50
51    def test_note2midi_out_of_range(self):
[f552e9e]52        " fails when passed a out of range note"
[33102ab]53        self.assertRaises(ValueError, note2midi, 'A9')
54
[f552e9e]55    def test_note2midi_wrong_data_type(self):
56        " fails when passed a non-string value "
57        self.assertRaises(TypeError, note2midi, 123)
58
[33102ab]59if __name__ == '__main__':
60    unittest.main()
Note: See TracBrowser for help on using the repository browser.