<s> import sys , struct <EOL> sys . path . append ( '<STR_LIT:..>' ) <EOL> PYTHON3 = True if sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:3> else False <EOL> import unittest <EOL> from pyknon . MidiFile import MIDIFile , MIDIHeader , MIDITrack , writeVarLength , frequencyTransform , returnFrequency <EOL> import sys <EOL> def get_byte ( midi , track , data ) : <EOL> if PYTHON3 : <EOL> return struct . unpack ( '<STR_LIT>' , bytes ( [ midi . tracks [ track ] . MIDIdata [ data ] ] ) ) [ <NUM_LIT:0> ] <EOL> else : <EOL> return struct . unpack ( '<STR_LIT>' , midi . tracks [ track ] . MIDIdata [ data ] ) [ <NUM_LIT:0> ] <EOL> class TestMIDIUtils ( unittest . TestCase ) : <EOL> def testWriteVarLength ( self ) : <EOL> self . assertEquals ( writeVarLength ( <NUM_LIT> ) , [ <NUM_LIT> ] ) <EOL> self . assertEquals ( writeVarLength ( <NUM_LIT> ) , [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertEquals ( writeVarLength ( <NUM_LIT> ) , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> self . assertEquals ( writeVarLength ( <NUM_LIT> ) , [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> def testAddNote ( self ) : <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . eventList [ <NUM_LIT:0> ] . type , "<STR_LIT>" ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . eventList [ <NUM_LIT:0> ] . pitch , <NUM_LIT:100> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . eventList [ <NUM_LIT:0> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . eventList [ <NUM_LIT:0> ] . duration , <NUM_LIT:1> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . eventList [ <NUM_LIT:0> ] . volume , <NUM_LIT:100> ) <EOL> def testDeinterleaveNotes ( self ) : <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:100> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:100> ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:2> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:2> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:3> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:3> ] . time , <NUM_LIT> ) <EOL> def testTimeShift ( self ) : <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> MyMIDI = MIDIFile ( <NUM_LIT:2> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> MyMIDI . addNote ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:6> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , - <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> MyMIDI = MIDIFile ( <NUM_LIT:2> ) <EOL> MyMIDI . addNote ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:100> , - <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> MyMIDI . addNote ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:100> ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT:0> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:0> ] . time , <NUM_LIT> ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:1> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:1> ] . MIDIEventList [ <NUM_LIT:1> ] . time , <NUM_LIT> ) <EOL> def testFrequency ( self ) : <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:0> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> self . assertEquals ( freq [ <NUM_LIT:2> ] , <NUM_LIT> ) <EOL> freq = frequencyTransform ( <NUM_LIT> ) <EOL> testFreq = <NUM_LIT> <EOL> accuracy = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> testFreq = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> testFreq = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> testFreq = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> testFreq = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> testFreq = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> testFreq = <NUM_LIT> <EOL> x = returnFrequency ( frequencyTransform ( testFreq ) ) <EOL> delta = abs ( testFreq - x ) <EOL> self . assertEquals ( delta < ( accuracy * testFreq ) , True ) <EOL> def testSysEx ( self ) : <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . addSysEx ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , struct . pack ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:1> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:2> ) , <NUM_LIT:3> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:4> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:5> ) , <NUM_LIT> ) <EOL> def testUniversalSysEx ( self ) : <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . addUniversalSysEx ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , struct . pack ( '<STR_LIT>' , <NUM_LIT> ) ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:1> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:2> ) , <NUM_LIT:6> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:4> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:5> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:7> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:8> ) , <NUM_LIT> ) <EOL> def testTuning ( self ) : <EOL> MyMIDI = MIDIFile ( <NUM_LIT:1> ) <EOL> MyMIDI . changeNoteTuning ( <NUM_LIT:0> , [ ( <NUM_LIT:1> , <NUM_LIT> ) , ( <NUM_LIT:2> , <NUM_LIT> ) ] ) <EOL> MyMIDI . close ( ) <EOL> self . assertEquals ( MyMIDI . tracks [ <NUM_LIT:0> ] . MIDIEventList [ <NUM_LIT:0> ] . type , '<STR_LIT>' ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:0> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:1> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:2> ) , <NUM_LIT:15> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:3> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:4> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:5> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:6> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:7> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:8> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:9> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:10> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:11> ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:12> ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT> ) , <NUM_LIT> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:15> ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT:16> ) , <NUM_LIT:0> ) <EOL> self . assertEquals ( get_byte ( MyMIDI , <NUM_LIT:0> , <NUM_LIT> ) , <NUM_LIT> ) <EOL> MIDISuite = unittest . TestLoader ( ) . loadTestsFromTestCase ( TestMIDIUtils ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . TextTestRunner ( verbosity = <NUM_LIT:1> ) . run ( MIDISuite ) </s>
