Skip to content

Commit

Permalink
Reorganize test packages and remove custom runners
Browse files Browse the repository at this point in the history
* Custom runners are unneeded with the builtin "unittest discovery"
  command.

* Reorganize test packages and avoid conflicts with the builtin
  `unittest` module.

* Remove unneeded path and suite boilerplate from tests.
  • Loading branch information
edudobay committed May 9, 2020
1 parent 4369741 commit 3788a4b
Show file tree
Hide file tree
Showing 34 changed files with 55 additions and 302 deletions.
14 changes: 8 additions & 6 deletions Makefile
Expand Up @@ -4,22 +4,24 @@ PATH := $(project_dir)/venv/bin:$(PATH)
all:

format:
python -m black mingus mingus_examples unittest
python -m black mingus mingus_examples tests

dev:
pip install -e '.[fft,fluidsynth]' -r requirements-dev.in

install:
pip install .

test:
(cd unittest; python run_tests.py)
test: test-unit

test-unit:
python -m unittest discover tests.unit

test-fluidsynth:
(cd unittest; python run_fluidsynth_tests.py)
python -m unittest tests.integration.test_fluidsynth

test-lilypond:
(cd unittest; python run_lilypond_tests.py)
python -m unittest tests.integration.test_lilypond

test-all: test test-fluidsynth test-lilypond

Expand Down Expand Up @@ -47,6 +49,6 @@ release: clean build sign-build upload tag

.PHONY: format \
dev install \
test test-fluidsynth test-lilypond test-all \
test test-unit test-fluidsynth test-lilypond test-all \
clean build \
upload tag release
Empty file added tests/__init__.py
Empty file.
File renamed without changes.
Empty file added tests/integration/__init__.py
Empty file.
Expand Up @@ -20,6 +20,9 @@ class test_fluidsynth(unittest.TestCase):
Check the :py:mod:`mingus.midi.fluidsynth` module for tips on finding
SoundFonts.
Remember: you need a running fluidsynth server process listening at port
9800 to pass this test.
"""

def setUp(self):
Expand Down Expand Up @@ -191,7 +194,3 @@ def test_composition(self):
c + t
c + t2
self.assertTrue(fluidsynth.play_Composition(c))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_fluidsynth)
Expand Up @@ -189,7 +189,3 @@ def test_to_png(self):
)
self.assertTrue(LilyPond.to_png(LilyPond.from_Bar(self.tbar), "pn2"))
self.assertTrue(LilyPond.to_png(LilyPond.from_Bar(self.mbar), "pn3"))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_LilyPond)
Empty file added tests/unit/__init__.py
Empty file.
Empty file.
13 changes: 3 additions & 10 deletions unittest/test_bar.py → tests/unit/containers/test_bar.py
@@ -1,15 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
from mingus.core.keys import Key
from mingus.containers.bar import Bar
from mingus.containers.note import Note
from mingus.containers.note_container import NoteContainer
from mingus.containers.mt_exceptions import MeterFormatError
import unittest
from mingus.core.keys import Key


class test_Bar(unittest.TestCase):
Expand Down Expand Up @@ -121,7 +118,3 @@ def test_determine_progression(self):
b + ["C", "E", "G"]
b + ["F", "A", "C"]
self.assertEqual([[0.0, ["I"]], [0.25, ["IV"]]], b.determine_progression(True))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_Bar)
@@ -1,17 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
# noinspection PyUnresolvedReferences
from mingus.containers.composition import Composition
import unittest


class test_Composition(unittest.TestCase):
def setUp(self):
pass


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_Composition)
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
from mingus.containers.instrument import Instrument, Piano, Guitar
from mingus.containers.note_container import NoteContainer
import unittest


class test_Instrument(unittest.TestCase):
Expand Down Expand Up @@ -47,7 +45,3 @@ def test_can_play_notes(self):
False,
self.g.can_play_notes(NoteContainer(["A", "B", "C", "D", "E", "F", "G",])),
)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_Instrument)
12 changes: 3 additions & 9 deletions unittest/test_note.py → tests/unit/containers/test_note.py
@@ -1,12 +1,10 @@
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
from __future__ import absolute_import

sys.path += ["../"]
from mingus.containers.note import Note
import unittest

from mingus.containers.mt_exceptions import NoteFormatError
from mingus.containers.note import Note


class test_Note(unittest.TestCase):
Expand Down Expand Up @@ -114,7 +112,3 @@ def test_from_shorthand(self):
self.assertTrue(Note().from_shorthand("c") == Note("C-3"))
self.assertTrue(Note().from_shorthand("c'") == Note("C-4"))
self.assertTrue(Note().from_shorthand("c''''''") == Note("C-9"))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_Note)
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
from mingus.containers.note_container import NoteContainer
from mingus.containers.note import Note
import unittest
from mingus.containers.note_container import NoteContainer


class test_NoteContainers(unittest.TestCase):
Expand Down Expand Up @@ -137,7 +135,3 @@ def test_is_dissonant(self):
self.assertTrue(not NoteContainer().from_chord("C").is_dissonant())
self.assertTrue(not NoteContainer().from_chord("G").is_dissonant())
self.assertTrue(not NoteContainer().from_chord("Dm").is_dissonant())


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_NoteContainers)
11 changes: 3 additions & 8 deletions unittest/test_suite.py → tests/unit/containers/test_suite.py
@@ -1,17 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
# noinspection PyUnresolvedReferences
from mingus.containers.suite import Suite
import unittest


class test_Suite(unittest.TestCase):
def setUp(self):
pass


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_Suite)
13 changes: 3 additions & 10 deletions unittest/test_track.py → tests/unit/containers/test_track.py
@@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
from mingus.containers.track import Track
from mingus.containers.bar import Bar
from mingus.containers.instrument import Instrument, Piano, Guitar
import unittest
from mingus.containers.track import Track


class test_Track(unittest.TestCase):
Expand All @@ -29,7 +26,3 @@ def test_transpose(self):
s + "E"
s + "G#"
self.assertEqual(s, t)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_Track)
Empty file added tests/unit/core/__init__.py
Empty file.
4 changes: 0 additions & 4 deletions unittest/test_chords.py → tests/unit/core/test_chords.py
Expand Up @@ -468,7 +468,3 @@ def test_determine_polychord(self):
lambda x: chords.determine_polychords(x, True),
"polychord naming",
)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_chords)
10 changes: 2 additions & 8 deletions unittest/test_intervals.py → tests/unit/core/test_intervals.py
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
import mingus.core.intervals as intervals
import unittest


class test_intervals(unittest.TestCase):
Expand Down Expand Up @@ -396,7 +394,3 @@ def test_is_dissonant(self):
self.assertTrue(intervals.is_dissonant("C", "F#"))
self.assertTrue(intervals.is_dissonant("C", "Bb"))
self.assertTrue(intervals.is_dissonant("C", "B"))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_intervals)
11 changes: 2 additions & 9 deletions unittest/test_keys.py → tests/unit/core/test_keys.py
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
import unittest

sys.path += ["../"]
import mingus.core.keys as keys
from mingus.core.mt_exceptions import NoteFormatError, KeyError
import unittest


class test_keys(unittest.TestCase):
Expand Down Expand Up @@ -71,7 +68,3 @@ def test_relative_minor(self):
"The minor of %s is not %s, expecting %s"
% (k, keys.relative_minor(k), known[k]),
)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_keys)
13 changes: 4 additions & 9 deletions unittest/test_meter.py → tests/unit/core/test_meter.py
@@ -1,13 +1,12 @@
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
from __future__ import absolute_import

sys.path += ["../"]
import mingus.core.meter as meter
import unittest

from six.moves import range

import mingus.core.meter as meter


class test_meter(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -96,7 +95,3 @@ def test_is_asymmetrical(self):

def test_is_full(self):
pass


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_meter)
4 changes: 0 additions & 4 deletions unittest/test_notes.py → tests/unit/core/test_notes.py
Expand Up @@ -108,7 +108,3 @@ def test_diminish(self):
"The diminished note of %s is not %s, expecting %s"
% (x, notes.diminish(x), known[x]),
)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_notes)
Expand Up @@ -146,7 +146,3 @@ def test_determine(self):
self.assertEqual(
["bii", "bIVM6"], progressions.determine(["Db", "Fb", "Ab"], "C", True)
)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_progressions)
11 changes: 2 additions & 9 deletions unittest/test_scales.py → tests/unit/core/test_scales.py
@@ -1,12 +1,9 @@
from __future__ import absolute_import

# -*- coding: utf-8 -*-
from __future__ import absolute_import

import sys
import unittest

sys.path += ["../"]
import mingus.core.scales as scales
import unittest


class test_scales(unittest.TestCase):
Expand Down Expand Up @@ -450,7 +447,3 @@ def test_not_equal(self):
self.assertNotEqual(scales.NaturalMinor("A"), scales.MelodicMinor("A"))
self.assertNotEqual(scales.Major("F"), scales.Major("D"))
self.assertNotEqual(scales.Ionian("E"), scales.Dorian("E"))


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_scales)
4 changes: 0 additions & 4 deletions unittest/test_value.py → tests/unit/core/test_value.py
Expand Up @@ -84,7 +84,3 @@ def test_septuplet(self):
self.assertEqual(value.septuplet(32, False), 28)
self.assertEqual(value.septuplet(64, False), 56)
self.assertEqual(value.septuplet(128, False), 112)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_value)
File renamed without changes.
File renamed without changes.
Empty file added tests/unit/extra/__init__.py
Empty file.
18 changes: 8 additions & 10 deletions unittest/test_fft.py → tests/unit/extra/test_fft.py
@@ -1,27 +1,25 @@
from __future__ import absolute_import

# -*- coding: utf-8 -*-
import sys
from __future__ import absolute_import

sys.path += ["../"]
import unittest

from pkg_resources import resource_filename

import mingus.extra.fft as fft
from mingus.containers import *


class test_fft(unittest.TestCase):
def setUp(self):
(self.data, self.freq, self.bits) = fft.data_from_file("440_sine_clean.wav")
(self.data, self.freq, self.bits) = fft.data_from_file(
resource_filename(__name__, "440_sine_clean.wav")
)

def test_find_Note(self):
self.assertEqual(Note("A"), fft.find_Note(self.data, self.freq, self.bits))

def test_find_melody(self):
self.assertEqual(
[(Note("A-4"), 86), (Note("A-5"), 86)],
fft.find_melody("440_880_clean.wav", 512)[:2],
fft.find_melody(resource_filename(__name__, "440_880_clean.wav"), 512)[:2],
)


def suite():
return unittest.TestLoader().loadTestsFromTestCase(test_fft)

0 comments on commit 3788a4b

Please sign in to comment.