Showing the changes to python (1 of 1 file). Show all
Unified · Split
| @@ -4,8 +4,8 @@ · 3 unmodified lines | |||
| 4 | from __future__ import unicode_literals | 4 | from __future__ import unicode_literals |
| 5 | 5 | ||
| 6 | from aubio import note2midi, freq2note, note2freq, float_type | 6 | from aubio import note2midi, freq2note, note2freq, float_type |
| 7 | from nose2.tools import params | 7 | from numpy.testing import TestCase |
| 8 | import unittest | 8 | from ._tools import parametrize, assert_raises |
| 9 | 9 | ||
| 10 | list_of_known_notes = ( | 10 | list_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 | ||
| 47 | class note2midi_good_values(unittest.TestCase): | 47 | class 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 sys | 60 | 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.12 | 63 | # 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 | raise | 67 | raise |
| 68 | 68 | ||
| 69 | class note2midi_wrong_values(unittest.TestCase): | 69 | class 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) | 107 | class 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 | ||
| 112 | class freq2note_simple_test(unittest.TestCase): | 114 | class 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 | ||
| 122 | class note2freq_simple_test(unittest.TestCase): | 124 | class 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 | ||
| 135 | if __name__ == '__main__': | 137 | if __name__ == '__main__': |
| 136 | import nose2 | 138 | from unittest import main |
| 137 | nose2.main() | 139 | main() |