python/tests/test_{midi2note,note2midi}.py: use nose2.params, add unicode tests
authorPaul Brossier <piem@piem.org>
Fri, 2 Dec 2016 12:44:12 +0000 (13:44 +0100)
committerPaul Brossier <piem@piem.org>
Fri, 2 Dec 2016 12:44:12 +0000 (13:44 +0100)
python/tests/test_midi2note.py
python/tests/test_note2midi.py

index 1c2ccf5..056738e 100755 (executable)
@@ -2,6 +2,7 @@
 # -*- coding: utf-8 -*-
 
 from aubio import midi2note
+from nose2.tools import params
 import unittest
 
 list_of_known_midis = (
@@ -16,10 +17,10 @@ list_of_known_midis = (
 
 class midi2note_good_values(unittest.TestCase):
 
-    def test_midi2note_known_values(self):
+    @params(*list_of_known_midis)
+    def test_midi2note_known_values(self, midi, note):
         " known values are correctly converted "
-        for midi, note in list_of_known_midis:
-            self.assertEqual ( midi2note(midi), note )
+        self.assertEqual ( midi2note(midi), note )
 
 class midi2note_wrong_values(unittest.TestCase):
 
@@ -40,4 +41,5 @@ class midi2note_wrong_values(unittest.TestCase):
         self.assertRaises(TypeError, midi2note, "a")
 
 if __name__ == '__main__':
-    unittest.main()
+    import nose2
+    nose2.main()
index 968c34a..7524a51 100755 (executable)
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 
 from aubio import note2midi, freq2note
+from nose2.tools import params
 import unittest
 
 list_of_known_notes = (
@@ -13,6 +14,9 @@ list_of_known_notes = (
         ( 'C3', 48 ),
         ( 'B3', 59 ),
         ( 'B#3', 60 ),
+        ( 'C\u266f4', 61 ),
+        ( 'C\U0001D12A4', 62 ),
+        ( 'E\U0001D12B4', 62 ),
         ( 'A4', 69 ),
         ( 'A#4', 70 ),
         ( 'Bb4', 70 ),
@@ -27,10 +31,10 @@ list_of_known_notes = (
 
 class note2midi_good_values(unittest.TestCase):
 
-    def test_note2midi_known_values(self):
+    @params(*list_of_known_notes)
+    def test_note2midi_known_values(self, note, midi):
         " known values are correctly converted "
-        for note, midi in list_of_known_notes:
-            self.assertEqual ( note2midi(note), midi )
+        self.assertEqual ( note2midi(note), midi )
 
 class note2midi_wrong_values(unittest.TestCase):
 
@@ -74,4 +78,5 @@ class freq2note_simple_test(unittest.TestCase):
         self.assertEqual("A4", freq2note(441))
 
 if __name__ == '__main__':
-    unittest.main()
+    import nose2
+    nose2.main()