History

[tests] use _tools in test_note2midi

Paul Brossier committed 8 years ago

Commit 86deeed1 parent 4c1eff41 file · +17 −15Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/test_note2midi.py+17−15
@@ -4,8 +4,8 @@ · 3 unmodified lines
4from __future__ import unicode_literals4from __future__ import unicode_literals
5 5
6from aubio import note2midi, freq2note, note2freq, float_type6from aubio import note2midi, freq2note, note2freq, float_type
7from nose2.tools import params7from numpy.testing import TestCase
8import unittest8from ._tools import parametrize, assert_raises
9 9
10list_of_known_notes = (10list_of_known_notes = (
11 ( 'C-1', 0 ),11 ( 'C-1', 0 ),
@@ -44,29 +44,29 @@ list_of_unknown_notes = ( · 32 unmodified lines
44 ( '2' ),44 ( '2' ),
45 )45 )
46 46
47class note2midi_good_values(unittest.TestCase):47class Test_note2midi_good_values:
48 48
49 @params(*list_of_known_notes)49 @parametrize('note, midi', list_of_known_notes)
50 def test_note2midi_known_values(self, note, midi):50 def test_note2midi_known_values(self, note, midi):
51 " known values are correctly converted "51 " known values are correctly converted "
52 self.assertEqual ( note2midi(note), midi )52 assert note2midi(note) == midi
53 53
54 @params(*list_of_known_notes_with_unicode_issues)54 @parametrize('note, midi', list_of_known_notes_with_unicode_issues)
55 def test_note2midi_known_values_with_unicode_issues(self, note, midi):55 def test_note2midi_known_values_with_unicode_issues(self, note, midi):
56 " known values are correctly converted, unless decoding is expected to fail"56 " known values are correctly converted, unless decoding is expected to fail"
57 try:57 try:
58 self.assertEqual ( note2midi(note), midi )58 assert note2midi(note) == midi
59 except UnicodeEncodeError as e:59 except UnicodeEncodeError as e:
60 import sys60 import sys
61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"61 strfmt = "len(u'\\U0001D12A') != 1, excpected decoding failure | {:s} | {:s} {:s}"
62 strres = strfmt.format(e, sys.platform, sys.version)62 strres = strfmt.format(e, sys.platform, sys.version)
63 # happens with: darwin 2.7.10, windows 2.7.1263 # happens with: darwin 2.7.10, windows 2.7.12
64 if len('\U0001D12A') != 1 and sys.version[0] == '2':64 if len('\U0001D12A') != 1 and sys.version[0] == '2':
65 self.skipTest(strres + " | upgrade to Python 3 to fix")65 skipTest(strres + " | upgrade to Python 3 to fix")
66 else:66 else:
67 raise67 raise
68 68
69class note2midi_wrong_values(unittest.TestCase):69class note2midi_wrong_values(TestCase):
70 70
71 def test_note2midi_missing_octave(self):71 def test_note2midi_missing_octave(self):
72 " fails when passed only one character"72 " fails when passed only one character"
@@ -104,12 +104,14 @@ class note2midi_wrong_values(unittest.TestCase): · 31 unmodified lines
104 " fails when passed a note with a note name longer than expected"104 " fails when passed a note with a note name longer than expected"
105 self.assertRaises(ValueError, note2midi, 'CB+-3')105 self.assertRaises(ValueError, note2midi, 'CB+-3')
106 106
107 @params(*list_of_unknown_notes)107class Test_note2midi_unknown_values:
108
109 @parametrize('note', list_of_unknown_notes)
108 def test_note2midi_unknown_values(self, note):110 def test_note2midi_unknown_values(self, note):
109 " unknown values throw out an error "111 " unknown values throw out an error "
110 self.assertRaises(ValueError, note2midi, note)112 assert_raises(ValueError, note2midi, note)
111 113
112class freq2note_simple_test(unittest.TestCase):114class freq2note_simple_test(TestCase):
113 115
114 def test_freq2note_above(self):116 def test_freq2note_above(self):
115 " make sure freq2note(441) == A4 "117 " make sure freq2note(441) == A4 "
@@ -119,7 +121,7 @@ class freq2note_simple_test(unittest.TestCase): · 3 unmodified lines
119 " make sure freq2note(439) == A4 "121 " make sure freq2note(439) == A4 "
120 self.assertEqual("A4", freq2note(439))122 self.assertEqual("A4", freq2note(439))
121 123
122class note2freq_simple_test(unittest.TestCase):124class note2freq_simple_test(TestCase):
123 125
124 def test_note2freq(self):126 def test_note2freq(self):
125 " make sure note2freq('A3') == 220"127 " make sure note2freq('A3') == 220"
@@ -133,5 +135,5 @@ class note2freq_simple_test(unittest.TestCase): · 7 unmodified lines
133 self.assertLess(abs(note2freq("A4")-440), 1.e-12)135 self.assertLess(abs(note2freq("A4")-440), 1.e-12)
134 136
135if __name__ == '__main__':137if __name__ == '__main__':
136 import nose2138 from unittest import main
137 nose2.main()139 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t