Skip to content

Commit 774fcbb

Browse files
committed
Parameterize inputs and use temp output dir in external tool tests
- Use "SOUNDFONT" environment variable instead of a hardcoded path - Use temporary directories when generating output files or interacting with tools that will generate output files.
1 parent 86177f3 commit 774fcbb

3 files changed

Lines changed: 44 additions & 12 deletions

File tree

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ format:
55
install:
66
python setup.py install
77

8+
test:
9+
(cd unittest; python run_tests.py)
10+
11+
test-fluidsynth:
12+
(cd unittest; python run_fluidsynth_tests.py)
13+
14+
test-lilypond:
15+
(cd unittest; python run_lilypond_tests.py)
16+
17+
test-all: test test-fluidsynth test-lilypond
18+
819
clean:
920
rm -rf build/ dist/
1021

unittest/test_fluidsynth.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
from __future__ import absolute_import
22

3-
# -*- coding: utf-8 -*-
4-
import sys
3+
import os
4+
import shutil
5+
import tempfile
6+
import time
7+
import unittest
8+
59
from six.moves import range
610

7-
sys.path += ["../"]
8-
from mingus.midi import fluidsynth
911
from mingus.containers import *
10-
import unittest
11-
import time
12+
from mingus.midi import fluidsynth
1213
from mingus.midi.sequencer_observer import SequencerObserver
1314

1415

1516
class test_fluidsynth(unittest.TestCase):
1617
def setUp(self):
17-
fluidsynth.init(
18-
"/home/bspaans/workspace/fluidsynth/ChoriumRevA.SF2", file="test.wav"
19-
)
18+
soundfont = os.getenv("SOUNDFONT")
19+
if soundfont is None:
20+
raise ValueError(
21+
"A soundfont (*.sf2) file path must be provided in the SOUNDFONT environment variable"
22+
)
23+
24+
self.tempdir = tempfile.mkdtemp()
25+
output_file = os.path.join(self.tempdir, "test.wav")
26+
27+
fluidsynth.init(soundfont, file=output_file)
2028
fluidsynth.set_instrument(0, 0)
2129
s = SequencerObserver()
2230
fluidsynth.midi.attach(s)
2331

32+
def tearDown(self):
33+
shutil.rmtree(self.tempdir)
34+
2435
def test_bar_velocity(self):
2536
b = Bar()
2637
n = Note("C")

unittest/test_lilypond.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from __future__ import absolute_import
22

3-
# -*- coding: utf-8 -*-
3+
import os
4+
import shutil
45
import sys
6+
import tempfile
7+
import unittest
58
from six.moves import map
69

7-
sys.path += ["../"]
8-
import unittest
910
import mingus.extra.lilypond as LilyPond
1011
import mingus.core.value as value
1112
from mingus.containers.note import Note
@@ -17,6 +18,11 @@
1718

1819
class test_LilyPond(unittest.TestCase):
1920
def setUp(self):
21+
# LilyPond output files are created in current working directory
22+
self.tempdir = tempfile.mkdtemp()
23+
self.oldcwd = os.getcwd()
24+
os.chdir(self.tempdir)
25+
2026
self.commonbar = Bar()
2127
self.ebar = Bar("E", (4, 4))
2228
self.fbar = Bar("F", (6, 8))
@@ -44,6 +50,10 @@ def setUp(self):
4450
self.composition2.add_track(self.track1)
4551
self.composition2.add_track(self.track2)
4652

53+
def tearDown(self):
54+
os.chdir(self.oldcwd)
55+
shutil.rmtree(self.tempdir)
56+
4757
def test_from_Note(self):
4858
self.assertEqual(LilyPond.from_Note(Note("C"), standalone=False), "c'")
4959
self.assertEqual(LilyPond.from_Note(Note("C#"), standalone=False), "cis'")

0 commit comments

Comments
 (0)