Changeset 41b985f for python/tests/test_note2midi.py
- Timestamp:
- Mar 12, 2017, 11:26:24 AM (7 years ago)
- Branches:
- sampler
- Children:
- bde49c4a
- Parents:
- 71f2e5f (diff), 67b6618 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/test_note2midi.py
r71f2e5f r41b985f 5 5 6 6 from aubio import note2midi, freq2note 7 from nose2.tools import params 7 8 import unittest 8 9 … … 14 15 ( 'B3', 59 ), 15 16 ( 'B#3', 60 ), 17 ( 'C♯4', 61 ), 16 18 ( 'A4', 69 ), 17 19 ( 'A#4', 70 ), 20 ( 'A♯4', 70 ), 21 ( 'A\u266f4', 70 ), 18 22 ( 'Bb4', 70 ), 19 23 ( 'B♭4', 70 ), 24 ( 'B\u266d4', 70 ), 20 25 ( 'G8', 115 ), 21 26 ( 'G♯8', 116 ), 22 27 ( 'G9', 127 ), 23 ( 'G\udd2a2', 45 ),24 ( 'B\ufffd2', 45 ),25 28 ( 'A♮2', 45 ), 29 ) 30 31 list_of_known_notes_with_unicode_issues = ( 32 ('C𝄪4', 62 ), 33 ('E𝄫4', 62 ), 34 ) 35 36 list_of_unknown_notes = ( 37 ( 'G\udd2a2' ), 38 ( 'B\ufffd2' ), 39 ( 'B\u266e\u266e2' ), 40 ( 'B\u266f\u266d3' ), 41 ( 'B33' ), 42 ( 'C.3' ), 43 ( 'A' ), 44 ( '2' ), 26 45 ) 27 46 28 47 class note2midi_good_values(unittest.TestCase): 29 48 30 def test_note2midi_known_values(self): 49 @params(*list_of_known_notes) 50 def test_note2midi_known_values(self, note, midi): 31 51 " known values are correctly converted " 32 for note, midi in list_of_known_notes: 52 self.assertEqual ( note2midi(note), midi ) 53 54 @params(*list_of_known_notes_with_unicode_issues) 55 def test_note2midi_known_values_with_unicode_issues(self, note, midi): 56 " known values are correctly converted, unless decoding is expected to fail" 57 try: 33 58 self.assertEqual ( note2midi(note), midi ) 59 except UnicodeEncodeError as e: 60 import sys 61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}" 62 strres = strfmt.format(e, sys.platform, sys.version) 63 # happens with: darwin 2.7.10, windows 2.7.12 64 if len('\U0001D12A') != 1 and sys.version[0] == '2': 65 self.skipTest(strres + " | upgrade to Python 3 to fix") 66 else: 67 raise 34 68 35 69 class note2midi_wrong_values(unittest.TestCase): … … 67 101 self.assertRaises(TypeError, note2midi, 123) 68 102 103 def test_note2midi_wrong_data_too_long(self): 104 " fails when passed a note with a note name longer than expected" 105 self.assertRaises(ValueError, note2midi, 'CB+-3') 106 107 @params(*list_of_unknown_notes) 108 def test_note2midi_unknown_values(self, note): 109 " unknown values throw out an error " 110 self.assertRaises(ValueError, note2midi, note) 69 111 70 112 class freq2note_simple_test(unittest.TestCase): … … 75 117 76 118 if __name__ == '__main__': 77 unittest.main() 119 import nose2 120 nose2.main()
Note: See TracChangeset
for help on using the changeset viewer.