feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change
on this file since 8986239 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
|
Rev | Line | |
---|
[7d89e61] | 1 | #! /usr/bin/env python |
---|
| 2 | # -*- coding: utf-8 -*- |
---|
[9ead7a9] | 3 | |
---|
| 4 | from aubio import midi2note |
---|
[d554321] | 5 | from nose2.tools import params |
---|
[9ead7a9] | 6 | import unittest |
---|
| 7 | |
---|
| 8 | list_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 | |
---|
[7d89e61] | 18 | class midi2note_good_values(unittest.TestCase): |
---|
[9ead7a9] | 19 | |
---|
[d554321] | 20 | @params(*list_of_known_midis) |
---|
| 21 | def test_midi2note_known_values(self, midi, note): |
---|
[9ead7a9] | 22 | " known values are correctly converted " |
---|
[d554321] | 23 | self.assertEqual ( midi2note(midi), note ) |
---|
[9ead7a9] | 24 | |
---|
[7d89e61] | 25 | class midi2note_wrong_values(unittest.TestCase): |
---|
[9ead7a9] | 26 | |
---|
| 27 | def test_midi2note_negative_value(self): |
---|
| 28 | " fails when passed a negative value " |
---|
| 29 | self.assertRaises(ValueError, midi2note, -2) |
---|
| 30 | |
---|
[0b6d23d] | 31 | def test_midi2note_large(self): |
---|
[9ead7a9] | 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 | |
---|
| 43 | if __name__ == '__main__': |
---|
[d554321] | 44 | import nose2 |
---|
| 45 | nose2.main() |
---|
Note: See
TracBrowser
for help on using the repository browser.