Example #1
0
 def setUp(self):
     """Set up stuff"""
     self.pathnames = ['test_path_1', 'test_path_2', 'test_path_3']
     self.ind_pieces = [MagicMock(spec=IndexedPiece) for _ in range(len(self.pathnames))]
     for i, ind_p in enumerate(self.ind_pieces):
         ind_p.metadata.return_value = self.pathnames[i]
     self.agg_p = AggregatedPieces(pieces=self.ind_pieces)
     self.agg_p2 = AggregatedPieces(pieces=[IndexedPiece(path) for path in self.pathnames])
Example #2
0
def Importer(location, metafile=None):
    """
    Import the file, website link, or directory of files designated by ``location`` to music21 
    format.

    :param location: Location of the file to import on the local disk.
    :type location: str
    :returns: An :class:`IndexedPiece` or an :class:`AggregatedPieces` object if the file passed 
        imports as a :class:`music21.stream.Score` or :class:`music21.stream.Opus` object
        respectively.
    :rtype: A new :class:`IndexedPiece` or :class:`AggregatedPieces` object.
    """
    pieces = []

    # load directory of pieces
    if isinstance(location, list) or os.path.isdir(location):
        directory_return = _import_directory(location, metafile)
        pieces.extend(directory_return[0])
        metafile = directory_return[1]

    # index piece if it is a file or a link
    elif os.path.isfile(location):
        pieces.extend(_import_file(location))

    else:
        raise RuntimeError(_UNKNOWN_INPUT)

    if len(pieces) == 1: # there was a single piece that imported as a score (not an opus)
        return(pieces[0]) # this returns an IndexedPiece object
    else: # there were multiple pieces or a single piece that imported as an opus
        return(AggregatedPieces(pieces=pieces, metafile=metafile))
Example #3
0
 def test_get_data_2(self):
     """try get_data() on an AggregatedPieces object with no pieces"""
     aps = AggregatedPieces()
     self.assertRaises(RuntimeWarning, aps.get_data, None, None)
     try:
         aps.get_data()
     except RuntimeWarning as r_warn:
         # pylint: disable=protected-access
         self.assertEqual(AggregatedPieces._NO_PIECES, r_warn.args[0])
Example #4
0
 def test_get_data_3(self):
     """integration test with a nested called to get_data, an ind_analyzer and a 
     combined_experimenter"""
     expected = pandas.Series([4.0,2.0,2.0,2.0,2.0,2.0,2.0,4.0],
                              index=['C3','C4','D4','E4','F4','G2','G4','Rest'])
     pieces = [Importer(os.path.join(VIS_PATH, 'tests', 'corpus', 'test_fermata_rest.xml'))]*2
     aps = AggregatedPieces(pieces=pieces)
     actual = aps.get_data(combined_experimenter='aggregator',
                           data=aps.get_data(ind_analyzer='noterest', combined_experimenter='frequency'))
     self.assertTrue(actual.iloc[:,0].equals(expected))
Example #5
0
 def test_date(self):
     date = ['----/--/-- to ----/--/--']
     agg = AggregatedPieces()._make_date_range(date)
     self.assertEqual(agg, None)