source: python/tests/test_note2midi.py @ d554321

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

python/tests/test_{midi2note,note2midi}.py: use nose2.params, add unicode tests

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