source: python/tests/test_note2midi.py @ ad65346

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretch
Last change on this file since ad65346 was 0b6d23d, checked in by Paul Brossier <piem@piem.org>, 9 years ago

python/tests: fix most prospect warnings

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