def test_midi_upload(self): global tune setTune(tune) # Testing a valid .mid file f = open("../tests/MIDITestFiles/e-flat-major-scale-on-bass-clef.mid", 'rb') self.app.post( '/', data={ 'fileInput': f, }, content_type = 'multipart/form-data', ) # The tune object should have found the midi file, in the uploads directory tune = getTune() self.assertEqual(tune.midifile, "static/uploads/e-flat-major-scale-on-bass-clef.mid") # Testing a non midi file f = open("../tests/MIDITestFiles/e-flat-major-scale-on-bass-clef.pdf", 'rb') self.app.post( '/', data={ 'fileInput': f, }, content_type='multipart/form-data', ) # The tune object should not have chosen the pdf, should remain unchanged tune = getTune() self.assertEqual(tune.midifile, "static/uploads/e-flat-major-scale-on-bass-clef.mid")
def test_wav_upload(self): global tune setTune(tune) # Testing a valid .wav file #f = open("../tests/WAVTestFiles/test1.wav", 'rb') #self.app.post( # '/', # data={ # 'fileInput': f, # }, # content_type='multipart/form-data', #) #f.close() # Testing a non wav file f = open("../tests/MIDITestFiles/e-flat-major-scale-on-bass-clef.pdf", 'rb') self.app.post( '/', data={ 'fileInput': f, }, content_type='multipart/form-data', )
def test_change_title_and_name(self): global tune setTune(tune) # test title change displays in PDF self.app.post('/', data=dict(titleInput="test my title!", ), follow_redirects=True) tune = getTune() ly_file = makeLilypondFile(tune) test_title = "test my title!".upper() self.assertEqual(str(ly_file.header_block.title), "\\markup { \"" + test_title + "\" }") # test contributors change displays in PDF self.app.post('/', data=dict( contributorsInput="good name, bad name, ok name", ), follow_redirects=True) tune2 = getTune() ly_file = makeLilypondFile(tune2) self.assertEqual(str(ly_file.header_block.composer), "\\markup { \"good name, bad name, ok name\" }")
def test_change_pitch(self): # make notes of all possible pitches and add to notes list letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] accidentals = [Tune.Accidental.FLAT, Tune.Accidental.SHARP] octaves = range(1, 11) notes = [] for letter in letters: for accidental in accidentals: for octave in octaves: pitch = Tune.Pitch() pitch.letter = letter pitch.accidental = accidental pitch.octave = octave note = Tune.Note() note.pitch = pitch note.duration = Tune.Duration.HALF note.onset = 0.0 notes.append(note) # make test tune object with the notes testTune = Tune.Tune() testTune.setEventsList(notes) # set the app's tune to be this test tune setTune(testTune) # send a request to edit the pitch for the note 1 in measure 0 for i in range(0, len(notes), 15): newPitch = Tune.Pitch() newPitch.letter = letters[ i % len(letters)] # just choose some letter in the letters list newPitch.accidental = accidentals[ i % len(accidentals )] # just choose some accident in the accidentals list newPitch.octave = octaves[ i % len(octaves)] # just choose some octave in the octaves list self.app.post('/', data=dict(note_submit="submit", measure_number='1', note_number='1', duration1='4', pitch=str(newPitch.letter), accidental=str(newPitch.accidental), octave=str(newPitch.octave), submit_type="edit"), follow_redirects=True) # after making post request to change the duration, make sure new tune object's note list has been updated updatedTune = getTune() noteI = updatedTune.events[1] pitchI = noteI.pitch self.assertEqual(newPitch.letter, newPitch.letter)
def test_title_and_name_input(self): global tune setTune(tune) # test valid title self.app.post('/', data=dict(titleInput="test my title!", ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (newline character) self.app.post('/', data=dict(titleInput="my\\ntitle!", ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (too long) self.app.post( '/', data=dict( titleInput= "test my titlelskdjflajdf;lakjsdf;lkajsdf;lkjas;dsdlkfjlskdjfldkfjlksjdflkfjlskdfjlsdfjoiwehgoaihgoishegoishegoishegoishegoiahseogahlskjdflk", ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (only spaces) self.app.post('/', data=dict(titleInput=" "), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (empty string) self.app.post('/', data=dict(titleInput=""), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test valid contributors self.app.post( '/', data=dict(contributorsInput="good name, good name, good name"), follow_redirects=True) tune = getTune() self.assertEqual(tune.contributors, "good name, good name, good name")
def test_title_and_name_input(self): global tune setTune(tune) # test valid title self.app.post('/', data=dict( titleInput="test my title!", ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title,"test my title!".upper()) # test invalid title (newline character) self.app.post('/', data=dict( titleInput="my\\ntitle!", ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (too long) self.app.post('/', data=dict( titleInput="test my titlelskdjflajdf;lakjsdf;lkajsdf;lkjas;dsdlkfjlskdjfldkfjlksjdflkfjlskdfjlsdfjoiwehgoaihgoishegoishegoishegoishegoiahseogahlskjdflk", ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (only spaces) self.app.post('/', data=dict( titleInput=" " ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test invalid title (empty string) self.app.post('/', data=dict( titleInput="" ), follow_redirects=True) tune = getTune() self.assertEqual(tune.title, "test my title!".upper()) # test valid contributors self.app.post('/', data=dict( contributorsInput="good name, good name, good name" ), follow_redirects=True) tune = getTune() self.assertEqual(tune.contributors, "good name, good name, good name")
def test_change_pitch(self): # make notes of all possible pitches and add to notes list letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'] accidentals = [Tune.Accidental.FLAT, Tune.Accidental.SHARP] octaves = range(1, 11) notes = [] for letter in letters: for accidental in accidentals: for octave in octaves: pitch = Tune.Pitch() pitch.letter = letter pitch.accidental = accidental pitch.octave = octave note = Tune.Note() note.pitch = pitch note.duration = Tune.Duration.HALF note.onset = 0.0 notes.append(note) # make test tune object with the notes testTune = Tune.Tune() testTune.setEventsList(notes) # set the app's tune to be this test tune setTune(testTune) # send a request to edit the pitch for the note 1 in measure 0 for i in range(0, len(notes),15): newPitch = Tune.Pitch() newPitch.letter = letters[i % len(letters)] # just choose some letter in the letters list newPitch.accidental = accidentals[i %len(accidentals)] # just choose some accident in the accidentals list newPitch.octave = octaves[i % len(octaves)] # just choose some octave in the octaves list self.app.post('/', data=dict( note_submit="submit", measure_number='1', note_number='1', duration1='4', pitch=str(newPitch.letter), accidental=str(newPitch.accidental), octave=str(newPitch.octave), submit_type="edit" ), follow_redirects=True) # after making post request to change the duration, make sure new tune object's note list has been updated updatedTune = getTune() noteI = updatedTune.events[1] pitchI = noteI.pitch self.assertEqual(newPitch.letter, newPitch.letter)
def test_change_duration(self): # make notes and add to the list notes durations = [ Tune.Duration.QUARTER, Tune.Duration.QUARTER, Tune.Duration.QUARTER, Tune.Duration.QUARTER ] notes = [] curr_onset = 0.0 for duration in durations: pitch = Tune.Pitch() pitch.letter = "a" pitch.octave = 5 note = Tune.Note() note.pitch = pitch note.duration = duration note.onset = curr_onset curr_onset += 0.25 notes.append(note) # make test tune object with the notes testTune = Tune.Tune() testTune.setTimeSignature((4, 4)) testTune.setEventsList(notes) # set the app's tune to be this test tune setTune(testTune) # for each note, send a request to edit the duration for i in range(0, len(durations)): newDuration = durations[len(durations) - i - 1] self.app.post('/', data=dict(note_submit="submit", measure_number='1', note_number='1', noteIndex='0', duration0='1', duration1=str(newDuration), submit_type="edit"), follow_redirects=True) # after making post request to change the duration, make sure new tune object's note list has been updated updatedTune = getTune() noteI = updatedTune.events[i] durationI = noteI.duration self.assertEqual(durationI, newDuration)
def test_change_duration(self): # make notes and add to the list notes durations = [Tune.Duration.QUARTER, Tune.Duration.QUARTER, Tune.Duration.QUARTER, Tune.Duration.QUARTER] notes = [] curr_onset = 0.0 for duration in durations: pitch = Tune.Pitch() pitch.letter = "a" pitch.octave = 5 note = Tune.Note() note.pitch = pitch note.duration = duration note.onset = curr_onset curr_onset += 0.25 notes.append(note) # make test tune object with the notes testTune = Tune.Tune() testTune.setTimeSignature((4,4)) testTune.setEventsList(notes) # set the app's tune to be this test tune setTune(testTune) # for each note, send a request to edit the duration for i in range(0,len(durations)): newDuration = durations[len(durations)-i-1] self.app.post('/', data=dict( note_submit="submit", measure_number='1', note_number='1', noteIndex='0', duration0='1', duration1=str(newDuration), submit_type="edit" ), follow_redirects=True) # after making post request to change the duration, make sure new tune object's note list has been updated updatedTune = getTune() noteI = updatedTune.events[i] durationI = noteI.duration self.assertEqual(durationI,newDuration)
def test_get_notes_by_measure(self): global tune setTune(tune) # making test tune notes = [] for n in range(4): note1 = Tune.Event() note1.pitch = Tune.Pitch() note1.letter = "c" note1.duration = (1, 1) notes.append(note1) tune.setEventsList(notes) # test split measures to split notes into groups by measure self.assertEqual(4, len(tunetoMeasures(tune))) # test for empty measures edge case emptyTune = Tune.Tune() self.assertEqual(0, len(tunetoMeasures(emptyTune))) # test output of tunetoMeasures to return a note by measure outputMeasures = tunetoMeasures(tune) note1 = Tune.Note() note1.pitch = Tune.Pitch() note1.pitch.letter = "c" note1.pitch.octave = 4 note1.duration = (1, 1) testNote = note1 self.assertEqual(testNote.getPitch()[0].letter, outputMeasures[0][0].getPitch()[0].letter) self.assertEqual(testNote.duration, outputMeasures[0][0].duration) self.assertEqual(testNote.getPitch()[0].accidental, outputMeasures[0][0].getPitch()[0].accidental) self.assertEqual(testNote.getPitch()[0].octave, outputMeasures[0][0].getPitch()[0].octave) self.assertEqual(1, len(outputMeasures[1]))
def test_json_upload(self): print "test_json_upload" global tune setTune(tune) # Testing a valid .json file f = open("../tests/JSONTestFiles/tune.json", 'rb') self.app.post( '/', data={ 'jsonInput': f, }, content_type='multipart/form-data', ) f.close() f = open("../tests/JSONTestFiles/tune.json", 'r') r = f.read() f.close() lines_input = r.splitlines() tune = getTune() tune.TunetoJSON(filename='test-output.json') f1 = open("test-output.json", 'r') r1 = f1.read() f1.close() lines_output = r1.splitlines() output_len = len(lines_output) input_len = len(lines_input) self.assertEqual(output_len, input_len) for i in range(output_len): print i self.assertEqual(lines_output[i], lines_input[i]) print "test_json_upload passed"
def test_get_notes_by_measure(self): global tune setTune(tune) # making test tune notes = [] for n in range(4): note1 = Tune.Event() note1.pitch = Tune.Pitch() note1.letter = "c" note1.duration = (1,1) notes.append(note1) tune.setEventsList(notes) # test split measures to split notes into groups by measure self.assertEqual(4, len(tunetoMeasures(tune))) # test for empty measures edge case emptyTune = Tune.Tune() self.assertEqual(0, len(tunetoMeasures(emptyTune))) # test output of tunetoMeasures to return a note by measure outputMeasures = tunetoMeasures(tune) note1 = Tune.Note() note1.pitch = Tune.Pitch() note1.pitch.letter = "c" note1.pitch.octave = 4 note1.duration = (1, 1) testNote = note1 self.assertEqual(testNote.getPitch()[0].letter, outputMeasures[0][0].getPitch()[0].letter) self.assertEqual(testNote.duration, outputMeasures[0][0].duration) self.assertEqual(testNote.getPitch()[0].accidental, outputMeasures[0][0].getPitch()[0].accidental) self.assertEqual(testNote.getPitch()[0].octave, outputMeasures[0][0].getPitch()[0].octave) self.assertEqual(1, len(outputMeasures[1]))
def test_change_title_and_name(self): global tune setTune(tune) # test title change displays in PDF self.app.post('/', data=dict( titleInput="test my title!", ), follow_redirects=True) tune = getTune() ly_file = makeLilypondFile(tune) test_title = "test my title!".upper() self.assertEqual(str(ly_file.header_block.title), "\\markup { \"" + test_title + "\" }") # test contributors change displays in PDF self.app.post('/', data=dict( contributorsInput="good name, bad name, ok name", ), follow_redirects=True) tune2 = getTune() ly_file = makeLilypondFile(tune2) self.assertEqual(str(ly_file.header_block.composer), "\\markup { \"good name, bad name, ok name\" }")
def test_midi_upload(self): global tune setTune(tune) # Testing a valid .mid file f = open("../tests/MIDITestFiles/e-flat-major-scale-on-bass-clef.mid", 'rb') self.app.post( '/', data={ 'fileInput': f, }, content_type='multipart/form-data', ) # The tune object should have found the midi file, in the uploads directory tune = getTune() self.assertEqual(tune.midifile, "static/uploads/e-flat-major-scale-on-bass-clef.mid") # Testing a non midi file f = open("../tests/MIDITestFiles/e-flat-major-scale-on-bass-clef.pdf", 'rb') self.app.post( '/', data={ 'fileInput': f, }, content_type='multipart/form-data', ) # The tune object should not have chosen the pdf, should remain unchanged tune = getTune() self.assertEqual(tune.midifile, "static/uploads/e-flat-major-scale-on-bass-clef.mid")