예제 #1
0
 def test_part_ranges(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml')
     score = Importer(path)._score
     expected_range = [('E4', 'E5'), ('E3', 'B4'), ('F#3', 'A4'),
                       ('A2', 'C4')]
     actual_range = _find_part_ranges(score)
     self.assertEqual(expected_range, actual_range)
예제 #2
0
 def test_ngrams_1(self):
     """Integration test for ngrams."""
     expected = AllVoiceIntervalNGrams.series_maker(
         AllVoiceIntervalNGrams.two_grams)
     expected = pandas.DataFrame({
         ('ngram.NGramIndexer', 'Soprano,Bass Alto,Bass Tenor,Bass : Bass'):
         expected
     })
     v_setts = {
         'quality': False,
         'simple or compound': 'compound',
         'directed': True
     }
     h_setts = {
         'quality': False,
         'horiz_attach_later': True,
         'simple or compound': False,
         'directed': True
     }
     n_setts = {
         'n': 2,
         'horizontal': [('Bass', )],
         'brackets': True,
         'continuer': '1',
         'vertical': [('Soprano,Bass', 'Alto,Bass', 'Tenor,Bass')]
     }
     ind_piece = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv603.xml'))
     vt = ind_piece.get('vertical_interval', settings=v_setts)
     hz = ind_piece.get('horizontal_interval', settings=h_setts)
     actual = ind_piece.get('ngram', data=(vt, hz), settings=n_setts)
     self.assertTrue(actual.equals(expected))
 def test_duration_indexer_4(self):
     # Soprano part of bwv77.mxl which is a part with no ties
     expected = TestDurationIndexer.make_series(
         TestDurationIndexer.bwv77_soprano)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     ip._analyses['part_streams'] = ip._get_part_streams()
     actual = ip.get('duration').iloc[:, 0].dropna()
     self.assertTrue(actual.equals(expected))
예제 #4
0
 def test_dynamic_offset_method(self):
     # integration test for dynamic offset method call and execution
     expected = os.path.join(VIS_PATH, 'tests', 'expecteds', 'bwv77', 'dynamic_offset_method_test')
     expected = pandas.read_pickle(expected)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv77.mxl'))
     nr = ip.get('noterest')
     actual = ip.get('offset', data=nr, settings={'quarterLength': 'dynamic'})
     self.assertTrue(actual.equals(expected))
 def test_measure_indexer_4(self):
     # bwv77.mxl, which is a piece with a pick-up measure. All 4 parts have the same data.
     measure_data = pandas.Series(
         range(19), index=TestMeasureIndexer.bwv77_measure_index)
     expected = pandas.concat([measure_data] * 4, axis=1)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     actual = ip._get_measure()
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
예제 #6
0
 def test_opus76(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'sqOp76-4-i.midi')
     expected_title = 'sqOp76-4-i'
     expected_parts = ['Part 1', 'Part 2', 'Part 3', 'Part 4']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score.parts)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
 def test_measure_indexer_5(self):
     # A two-part test piece with no pick-up measure originally written to test fermata indexer.
     measure_data = pandas.Series([1, 2], index=[0.0, 4.0])
     expected = pandas.concat([measure_data] * 2, axis=1)
     ip = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus/test_fermata_rest.xml'))
     actual = ip.get('measure')
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
예제 #8
0
 def test_jos2308_krn(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'Jos2308.krn')
     expected_title = 'Jos2308'
     expected_parts = ['spine_3', 'spine_2', 'spine_1', 'spine_0']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
예제 #9
0
 def test_sinfony(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'sinfony.md')
     expected_title = 'Messiah'
     expected_parts = ['Violino I', 'Violino II', 'Viola', 'Bassi']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score.parts)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
예제 #10
0
 def test_bwv2(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml')
     expected_title = 'bwv2'
     expected_parts = ['Soprano', 'Alto', 'Tenor', 'Bass']
     the_score = Importer(path)._score
     actual_title = _find_piece_title(the_score)
     actual_parts = _find_part_names(the_score.parts)
     self.assertEqual(expected_title, actual_title)
     self.assertSequenceEqual(expected_parts, actual_parts)
예제 #11
0
 def test_fermata_indexer_2(self):
     """rest fermatas"""
     # Create expected.
     temp = [pandas.Series(['Fermata'], index=[6]), pandas.Series(['Fermata'], index=[6])]
     expected = pandas.concat(temp, axis=1).reindex(pandas.Index([0,1,2,3,4,6]))
     # Test.
     ind_piece = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'test_fermata_rest.xml'))
     expected.columns = ind_piece.metadata('parts')
     actual = ind_piece._get_fermata()
     self.assertTrue(actual['fermata.FermataIndexer'].equals(expected))
예제 #12
0
 def test_multistop_indexer_2(self):
     # Integration test of a whole piece, the string quarted in the test corpus.
     ip = Importer(
         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])
예제 #13
0
 def test_Importer3(self):
     path = 'vis/tests/corpus/elvisdownload/'
     folder = os.listdir(path)
     if '.DS_Store' in folder:
         folder.remove('.DS_Store')
     folder.remove('meta')
     new_f = []
     for f in folder:
         new_f.append(path + f)
     agg = Importer(new_f)
     self.assertTrue(isinstance(agg, AggregatedPieces))
 def test_duration_indexer_5(self):
     # Alto part of bwv603.mxl which is a part with ties. Also test that data argument is passed
     # correctly. Since the data argument is passed, these results should not be cached.
     expected = TestDurationIndexer.make_series(
         TestDurationIndexer.bwv603_alto)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip.get('duration',
                     data=(ip.get('noterest'),
                           ip._analyses['part_streams'])).iloc[:,
                                                               1].dropna()
     self.assertTrue(actual.equals(expected))
     self.assertTrue('duration' not in ip._analyses.keys())
 def test_note_beat_strength_indexer_6(self):
     # Soprano and bass parts of bwv603.xml
     # We won't verify all the parts, but we'll submit them all for analysis.
     expected = pandas.concat([
         TestNoteBeatStrengthIndexer.make_series(bwv603_soprano),
         TestNoteBeatStrengthIndexer.make_series(bwv603_bass)
     ],
                              axis=1)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip._get_beat_strength(
     )['meter.NoteBeatStrengthIndexer'].iloc[:, [0, 3]].dropna(how='all')
     expected.columns = actual.columns
     self.assertTrue(actual.equals(expected))
 def test_duration_indexer_6(self):
     # Soprano and bass parts of bwv603.xml
     # We won't verify all the parts, but we'll submit them all for analysis.
     expected = pandas.concat([
         TestDurationIndexer.make_series(
             TestDurationIndexer.bwv603_soprano),
         TestDurationIndexer.make_series(TestDurationIndexer.bwv603_bass)
     ],
                              axis=1)
     expected.columns = pandas.MultiIndex.from_product([
         ('meter.DurationIndexer', ), ('Soprano', 'Bass')
     ])
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip.get('duration').iloc[:, [0, 3]].dropna(how='all')
     self.assertTrue(actual.equals(expected))
예제 #17
0
    def test_fermata_indexer_1(self):
        """all-voice fermatas"""
        # Create expected.
        parts = [pandas.Series(['Fermata']*4, index=[10,19,31,46]),
                 pandas.Series(), pandas.Series(),
                 pandas.Series(['Fermata']*4, index=[10,19,31,46])]
        expected = pandas.concat(parts, axis=1)
        indx = pandas.Index(range(47))
        expected = expected.reindex(index=indx)
        expected.drop([11, 12, 20, 32], inplace=True)

        # Test.
        ind_piece = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv603.xml'))
        expected.columns = ind_piece.metadata('parts')
        actual = ind_piece._get_fermata()
        self.assertTrue(actual['fermata.FermataIndexer'].equals(expected))
예제 #18
0
 def test_diss_indexer_run_2(self):
     """
     Test the dissonance indexer on an entire real piece that has most of the dissonance types 
     and covers almost all of the logic, namely the "Kyrie" in the test corpus. NB: perhaps 
     this test should get moved to the integration tests file.
     """
     expected = pd.read_pickle(
         os.path.join(VIS_PATH, 'tests', 'expecteds',
                      'test_dissonance_thorough.pickle'))
     # Detection of Z's and O's was removed and so this old ground-truth is updated in this test with the two
     # following lines. If the dissonance indexer gets re-written, it would be good to go back to this old
     # ground truth without needing these two replace() calls.
     expected.replace('Z', '-', inplace=True)
     expected.replace('O', '-', inplace=True)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'Kyrie.krn'))
     actual = ip.get('dissonance')
     expected.columns = actual.columns  # the pickle file has old-style column names.
     assert_frame_equal(actual, expected)
예제 #19
0
    def test_noterest_indexer_4(self):
        # Combine three previous tests to avoid re-importing the same piece multiple times.
        # Soprano part of bwv77.mxl
        expected = TestNoteRestIndexer.make_series(
            TestNoteRestIndexer.bwv77_soprano)
        expected.name = 'Soprano'
        ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
        actual = ip._get_noterest()['noterest.NoteRestIndexer'].iloc[:,
                                                                     0].dropna(
                                                                     )
        self.assertTrue(actual.equals(expected))

        # Reset analysis dictionary and make the score just the bass part and do the same test.
        expected = TestNoteRestIndexer.make_series(
            TestNoteRestIndexer.bwv77_bass)
        expected.name = 'Bass'
        actual = ip._get_noterest()['noterest.NoteRestIndexer'].iloc[:,
                                                                     3].dropna(
                                                                     )
        self.assertTrue(actual.equals(expected))
 def test_ngrams_1(self):
     """Ngram integration test."""
     expected = AllVoiceIntervalNGrams.series_maker(
         AllVoiceIntervalNGrams.two_grams)
     expected = pandas.DataFrame({
         ('ngram.NGramIndexer', 'Soprano,Bass Alto,Bass Tenor,Bass : Bass'):
         expected
     })
     ind_piece = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml'))
     setts = {'quality': False, 'simple': False, 'horiz_attach_later': True}
     horiz_ints = ind_piece.get('horizontal_interval', settings=setts)
     vert_ints = ind_piece.get('vertical_interval', settings=setts)
     setts = {
         'n': 2,
         'continuer': '1',
         'horizontal': 'lowest',
         'vertical': [('Soprano,Bass', 'Alto,Bass', 'Tenor,Bass')],
         'brackets': True,
     }
     actual = ind_piece.get('ngram',
                            data=(vert_ints, horiz_ints),
                            settings=setts)
     self.assertTrue(actual.equals(expected))
 def test_note_beat_strength_indexer_5(self):
     # Alto part of bwv603.mxl which is a part with ties
     expected = TestNoteBeatStrengthIndexer.make_series(bwv603_alto)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv603.xml'))
     actual = ip._get_beat_strength().iloc[:, 1].dropna()
     self.assertTrue(actual.equals(expected))
예제 #22
0
 def test_Importer2(self):
     directory = 'vis/tests/corpus/elvisdownload2'
     agg = Importer(directory)
     self.assertTrue(isinstance(agg, AggregatedPieces))
예제 #23
0
 def test_piece_range(self):
     path = os.path.join(VIS_PATH, 'tests', 'corpus', 'bwv2.xml')
     score = Importer(path)._score
     expected_range = ('A2', 'E5')
     actual_range = _find_piece_range(score)
     self.assertEqual(expected_range, actual_range)
예제 #24
0
 def test_multistop_indexer_3(self):
     # Integration test on a piece with multiple voices in each part
     ip = Importer(
         os.path.join(VIS_PATH, 'tests', 'corpus', 'prelude28-20.mid'))
     actual = ip.get('multistop')
     self.assertTrue(8 == len(actual.columns))
 def test_note_beat_strength_indexer_4(self):
     # Soprano part of bwv77.mxl which is a part with no ties
     expected = TestNoteBeatStrengthIndexer.make_series(bwv77_soprano)
     ip = Importer(os.path.join(VIS_PATH, 'tests', 'corpus/bwv77.mxl'))
     actual = ip._get_beat_strength().iloc[:, 0].dropna()
     self.assertTrue(actual.equals(expected))