Skip to content

Commit

Permalink
fix: add test for #16
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Arndt <chris@chrisarndt.de>
  • Loading branch information
SpotlightKid committed Aug 21, 2023
1 parent f9a8a36 commit 703fa6e
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions tests/test_midifilewriter.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
#!/usr/bin/env python3
"""Write MIDI file with the following events:

format: 0, # of tracks: 1, division: 480
----------------------------------
Start of track #0
Sequence name - 'Type 0'
Tempo: val:500000 (125.0 bpm)
Time signature: 4/4 24 8
Note on - ch:00, note:48h, vel:64h time:0
Note off - ch:00, note:48h, vel:40h time:480
End of track
End of file
"""

import io
import os
from io import BytesIO
from os.path import dirname, isdir, join

import pytest # noqa

from miditk.common.constants import END_OF_TRACK, META_EVENT, POLY_PRESSURE
from miditk.smf.writer import MidiFileWriter


def test_write_type0():
"""Write MIDI file with the following events:
format: 0, # of tracks: 1, division: 480
----------------------------------
Start of track #0
Sequence name - 'Type 0'
Tempo: val:500000 (125.0 bpm)
Time signature: 4/4 24 8
Note on - ch:00, note:48h, vel:64h time:0
Note off - ch:00, note:48h, vel:40h time:480
End of track
End of file
"""
cmpfn = join(dirname(__file__), 'testdata', 'midiout.mid')
outdir = join(dirname(__file__), 'testoutput')
outfn = join(outdir, 'midiout.mid')
Expand Down Expand Up @@ -58,7 +59,7 @@ def test_write_type0():


def test_write_sysex_issue_7():
smf = io.BytesIO()
smf = BytesIO()
midi = MidiFileWriter(smf)
midi.header(format=0, num_tracks=1, tick_division=96)
midi.start_of_track(track=0)
Expand All @@ -67,3 +68,19 @@ def test_write_sysex_issue_7():
midi.eof()

assert b'\xf0\x07\xf0\xfd\x01\x02\x03\xf7' in smf.getvalue()


def test_write_poly_pressure():
smf = BytesIO()
channel = 10
midi = MidiFileWriter(smf)
midi.header(format=0, num_tracks=1, tick_division=96)
midi.start_of_track(track=0)
midi.poly_pressure(channel, 60, 127)
midi.end_of_track()
midi.eof()

assert smf.getvalue().endswith(bytes([
0, POLY_PRESSURE | channel, 60, 127, # Poly pressure event
0, META_EVENT, END_OF_TRACK, 0 # End of track meta event (len 0)
]))

0 comments on commit 703fa6e

Please sign in to comment.