source: python/tests/test_midi2note.py @ 6203a70

feature/constantq
Last change on this file since 6203a70 was d554321, checked in by Paul Brossier <piem@piem.org>, 8 years ago

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

  • Property mode set to 100755
File size: 1.3 KB
Line 
1#! /usr/bin/env python
2# -*- coding: utf-8 -*-
3
4from aubio import midi2note
5from nose2.tools import params
6import unittest
7
8list_of_known_midis = (
9        ( 0, 'C-1' ),
10        ( 1, 'C#-1' ),
11        ( 38, 'D2' ),
12        ( 48, 'C3' ),
13        ( 59, 'B3' ),
14        ( 60, 'C4' ),
15        ( 127, 'G9' ),
16        )
17
18class midi2note_good_values(unittest.TestCase):
19
20    @params(*list_of_known_midis)
21    def test_midi2note_known_values(self, midi, note):
22        " known values are correctly converted "
23        self.assertEqual ( midi2note(midi), note )
24
25class midi2note_wrong_values(unittest.TestCase):
26
27    def test_midi2note_negative_value(self):
28        " fails when passed a negative value "
29        self.assertRaises(ValueError, midi2note, -2)
30
31    def test_midi2note_large(self):
32        " fails when passed a value greater than 127 "
33        self.assertRaises(ValueError, midi2note, 128)
34
35    def test_midi2note_floating_value(self):
36        " fails when passed a floating point "
37        self.assertRaises(TypeError, midi2note, 69.2)
38
39    def test_midi2note_character_value(self):
40        " fails when passed a value that can not be transformed to integer "
41        self.assertRaises(TypeError, midi2note, "a")
42
43if __name__ == '__main__':
44    import nose2
45    nose2.main()
Note: See TracBrowser for help on using the repository browser.