'Test writing to a MIDI file and comparing it to the original Sequence.'

def CheckReadWriteMidi(self, filename):

    with tempfile.NamedTemporaryFile(prefix='MidiIoTest') as rewrite_file:
        original_midi = pretty_midi.PrettyMIDI(filename)
        original_midi.write(rewrite_file.name)
        source_midi = pretty_midi.PrettyMIDI(rewrite_file.name)
        sequence_proto = midi_io.midi_to_sequence_proto(source_midi)
    with tempfile.NamedTemporaryFile(prefix='MidiIoTest') as temp_file:
        midi_io.sequence_proto_to_midi_file(sequence_proto, temp_file.name)
        created_midi = pretty_midi.PrettyMIDI(temp_file.name)
    self.CheckPrettyMidiAndSequence(created_midi, sequence_proto)
