Changeset 3aad0b1 for python/tests


Ignore:
Timestamp:
Dec 3, 2016, 4:03:47 AM (8 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler, yinfft+
Children:
c0c3f33
Parents:
d554321
Message:

python/lib/aubio/midiconv.py: improve unicode handling, skip UnicodeEncodeError? on python 2.x

File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/tests/test_note2midi.py

    rd554321 r3aad0b1  
    1515        ( 'B3', 59 ),
    1616        ( 'B#3', 60 ),
    17         ( 'C\u266f4', 61 ),
    18         ( 'C\U0001D12A4', 62 ),
    19         ( 'E\U0001D12B4', 62 ),
     17        ( 'C♯4', 61 ),
    2018        ( 'A4', 69 ),
    2119        ( 'A#4', 70 ),
     20        ( 'A♯4', 70 ),
     21        ( 'A\u266f4', 70 ),
    2222        ( 'Bb4', 70 ),
    2323        ( 'B♭4', 70 ),
     24        ( 'B\u266d4', 70 ),
    2425        ( 'G8', 115 ),
    2526        ( 'G♯8', 116 ),
    2627        ( 'G9', 127 ),
    27         ( 'G\udd2a2', 45 ),
    28         ( 'B\ufffd2', 45 ),
    2928        ( 'A♮2', 45 ),
     29        )
     30
     31list_of_known_notes_with_unicode_issues = (
     32        ('C𝄪4', 62 ),
     33        ('E𝄫4', 62 ),
     34        )
     35
     36list_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' ),
    3045        )
    3146
     
    3651        " known values are correctly converted "
    3752        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:
     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
    3868
    3969class note2midi_wrong_values(unittest.TestCase):
     
    71101        self.assertRaises(TypeError, note2midi, 123)
    72102
     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)
    73111
    74112class freq2note_simple_test(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.