Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up tests by gently patching mido to not do useless work #44

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest


@pytest.fixture()
def disable_mido_checks(monkeypatch):
"""
Disable internal checks in `mido`, for performance.
"""
from mido.messages import messages

monkeypatch.setattr(messages, "check_msgdict", lambda d: d)


@pytest.fixture()
def disable_mido_merge_tracks(monkeypatch):
"""
Disallow `mido` from creating `merged_tracks` when files are loaded.

We don't need `merged_tracks` in our tests, and it's slow to create.

See https://github.com/mido/mido/pull/565.
akx marked this conversation as resolved.
Show resolved Hide resolved
TODO: this could maybe be removed after the
abovementioned PR is in a `mido` release.
"""
from mido.midifiles import midifiles

monkeypatch.setattr(midifiles, "merge_tracks", lambda tracks: None)
2 changes: 1 addition & 1 deletion tests/test_pianoroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@pytest.mark.parametrize("midi_path", MIDI_PATHS, ids=attrgetter("name"))
@pytest.mark.parametrize("test_set", test_sets)
def test_pianoroll(midi_path, test_set):
def test_pianoroll(midi_path, test_set, disable_mido_checks, disable_mido_merge_tracks):
"""Testing creating pianorolls of notes."""

# Set pitch range parameters
Expand Down
2 changes: 1 addition & 1 deletion tests/test_read_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.mark.parametrize("midi_path", MIDI_PATHS, ids=attrgetter("name"))
def test_load_dump(midi_path, tmp_path):
def test_load_dump(midi_path, tmp_path, disable_mido_checks, disable_mido_merge_tracks):
"""Test that a MIDI loaded and saved unchanged is indeed the save as before."""
midi1 = MidiFile(midi_path)
dump_path = tmp_path / midi_path.name
Expand Down
4 changes: 3 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


@pytest.mark.parametrize("midi_path", MIDI_PATHS[:5], ids=attrgetter("name"))
def test_remove_notes_with_no_duration(midi_path, tmp_path):
def test_remove_notes_with_no_duration(
midi_path, tmp_path, disable_mido_checks, disable_mido_merge_tracks
):
"""Test that a MIDI loaded and saved unchanged is indeed the save as before."""
# Load the MIDI file and removes the notes with durations <= 0
midi = MidiFile(midi_path)
Expand Down
Loading