Skip to content

Commit

Permalink
Tests: test suite for multistop indexer.
Browse files Browse the repository at this point in the history
There is some problem with pickling so I had to test using other means.
This may be related to pandas issue 3699 or 11564.
  • Loading branch information
alexandermorgan committed Sep 13, 2016
1 parent 2b9ba8f commit b39fab0
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
2 changes: 2 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from vis.tests import test_aggregated_pieces
from vis.tests import bwv2_integration_tests as bwv2
from vis.tests import bwv603_integration_tests as bwv603
# NB: The WorkflowManager is deprecated, though most of its tests still pass.
# from vis.tests import test_workflow
# from vis.tests import test_workflow_integration
# from vis.tests import test_workflow_experiments
Expand All @@ -67,6 +68,7 @@
# test_indexer.UNIQUE_OFFSETS_SUITE, # No longer called.
test_fermata_indexer.FERMATA_INDEXER_SUITE,
test_note_rest_indexer.NOTE_REST_INDEXER_SUITE,
test_note_rest_indexer.MULTI_STOP_INDEXER_SUITE,
test_duration_indexer.DURATION_INDEXER_SUITE,
test_note_beat_strength_indexer.NOTE_BEAT_STRENGTH_INDEXER_SUITE, # 'module' object has no attribute 'TimeSignature'
test_measure_indexer.MEASURE_INDEXER_SUITE,
Expand Down
64 changes: 51 additions & 13 deletions vis/tests/test_note_rest_indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def make_series(lotuples):
vals = [x[1] for x in lotuples]
return pandas.Series(vals, index=new_index)

def test_note_rest_indexer_func_1(self):
def test_noterest_ind_func_1(self):
# Check the indexer_func on note, rest, and chord objects
expected = pandas.Series(('A-4', 'Rest', 'F#5'))
n1 = note.Note('A-4')
Expand All @@ -99,16 +99,7 @@ def test_note_rest_indexer_func_1(self):
actual = temp.apply(noterest.noterest_ind_func)
self.assertTrue(actual.equals(expected))

def test_note_rest_unpack_chords_1(self):
# Make sure that unpack_chords expands chords the right way.
expected = pandas.concat((pandas.Series(('A-4', 'Rest', 'A-4')),
pandas.Series((None, None, 'D#5')),
pandas.Series((None, None, 'F#5'))), axis=1)
temp = pandas.concat((pandas.Series((('A-4',), ('Rest',), ['A-4', 'D#5', 'F#5'])),), axis=1)
actual = noterest.unpack_chords(temp)
self.assertTrue(actual.equals(expected))

def test_note_rest_indexer_1(self):
def test_noterest_indexer_1(self):
# When the parts are empty
expected = pandas.DataFrame({'0': pandas.Series(), '1': pandas.Series()})
nr_indexer = noterest.NoteRestIndexer(expected)
Expand Down Expand Up @@ -139,15 +130,15 @@ def test_note_rest_indexer_1(self):
# self.assertSequenceEqual(list(expected[key].index), list(actual[key].index))
# self.assertSequenceEqual(list(expected[key]), list(actual[key]))

def test_note_rest_indexer_2(self):
def test_noterest_indexer_2(self):
# When there are a bunch of notes
expected = pandas.DataFrame({'0': pandas.Series([u'C4' for _ in range(10)])})
test_score = pandas.DataFrame({'0': pandas.Series([note.Note('C4') for i in range(10)])})
nr_indexer = noterest.NoteRestIndexer(test_score)
actual = nr_indexer.run()['noterest.NoteRestIndexer']
self.assertTrue(actual.equals(expected))

def test_note_rest_indexer_3(self):
def test_noterest_indexer_3(self):
# Combine three previous tests to avoid re-importing the same piece multiple times.
# Soprano part of bwv77.mxl
expected = pandas.DataFrame({'0': TestNoteRestIndexer.make_series(TestNoteRestIndexer.bwv77_soprano)})
Expand All @@ -165,7 +156,54 @@ def test_note_rest_indexer_3(self):
self.assertTrue(actual.equals(expected))


class TestMultiStopIndexer(unittest.TestCase):

def test_unpack_chords_1(self):
# Make sure that unpack_chords expands chords the right way.
expected = pandas.concat((pandas.Series(('A-4', 'Rest', 'A-4')),
pandas.Series((None, None, 'D#5')),
pandas.Series((None, None, 'F#5'))), axis=1)
temp = pandas.concat((pandas.Series((('A-4',), ('Rest',), ['A-4', 'D#5', 'F#5'])),), axis=1)
actual = noterest.unpack_chords(temp)
self.assertTrue(actual.equals(expected))

def test_multistop_ind_func_1(self):
# Check the indexer_func on note, rest, and chord objects
expected = pandas.Series((('A-4',), ('Rest',), ['F#5', 'D#5', 'A-4']))
n1 = note.Note('A-4')
n2 = note.Note('D#5')
n3 = note.Note('F#5')
r1 = note.Rest()
c1 = chord.Chord([n3, n2, n1])
temp = pandas.Series((n1, r1, c1))
actual = temp.apply(noterest.multistop_ind_func)
self.assertTrue(actual.equals(expected))

def test_multistop_indexer_1(self):
# When the parts are empty
expected = pandas.DataFrame({'0': pandas.Series(), '1': pandas.Series()})
mu_indexer = noterest.MultiStopIndexer(expected)
actual = mu_indexer.run()['noterest.MultiStopIndexer']
self.assertTrue(actual.equals(expected))

def test_multistop_indexer_2(self):
# Integration test of a whole piece, the string quarted in the test corpus.
ip = IndexedPiece(os.path.join(VIS_PATH, 'tests', 'corpus', 'sqOp76-4-i.midi'))
actual = ip._get_multistop()
# Until we figure out why pickling isn't working:
self.assertTrue(10 == len(actual.columns))
self.assertTrue(3286 == len(actual.index))
self.assertSequenceEqual([val for val in actual.count().values],
[2098, 41, 4, 1818, 131, 1, 1621, 15, 1232, 2])
# When we get pickling working again (just save to_pickle once):
# actual.to_pickle(os.path.join(VIS_PATH, 'tests', 'corpus', 'expecteds', 'test_multistop.pickle'))
# expected = pandas.read_pickle(os.path.join(VIS_PATH, 'tests', 'corpus', 'expecteds', 'test_multistop.pickle'))
# self.assertTrue(actual.equals(expected))



#--------------------------------------------------------------------------------------------------#
# Definitions #
#--------------------------------------------------------------------------------------------------#
NOTE_REST_INDEXER_SUITE = unittest.TestLoader().loadTestsFromTestCase(TestNoteRestIndexer)
MULTI_STOP_INDEXER_SUITE = unittest.TestLoader().loadTestsFromTestCase(TestMultiStopIndexer)

0 comments on commit b39fab0

Please sign in to comment.