예제 #1
0
    def test_table_1(self, mock_fdf):
        '''
        _make_table():

        - "count frequency" is True
        - file extension on "pathname" with period
        '''
        test_wm = WorkflowManager([])
        test_wm.settings(None, 'count frequency', True)  # just to be 100% clear
        mock_fdf.return_value = mock.MagicMock(spec_set=pandas.DataFrame)
        test_wm._result = mock_fdf.return_value  # to avoid a RuntimeError
        test_wm._previous_exp = 'intervals'  # to get the proper "exp_name"
        top_x = None
        threshold = None
        exp_name = 'Interval Frequency'
        pathname = 'test_path'

        test_wm._make_table('CSV', pathname + '.csv', top_x, threshold)  # pylint: disable=protected-access
        test_wm._make_table('Excel', pathname + '.xlsx', top_x, threshold)  # pylint: disable=protected-access
        test_wm._make_table('Stata', pathname + '.dta', top_x, threshold)  # pylint: disable=protected-access
        test_wm._make_table('HTML', pathname + '.html', top_x, threshold)  # pylint: disable=protected-access

        mock_fdf.return_value.to_csv.assert_called_once_with('test_path.csv')
        mock_fdf.return_value.to_stata.assert_called_once_with('test_path.dta')
        mock_fdf.return_value.to_excel.assert_called_once_with('test_path.xlsx')
        mock_fdf.return_value.to_html.assert_called_once_with('test_path.html')
        self.assertSequenceEqual([mock.call(top_x=top_x, threshold=threshold, name=exp_name) for _ in range(4)],
                                 mock_fdf.call_args_list)
예제 #2
0
    def test_table_3(self):
        '''
        _make_table():

        - "count frequency" is False
        - file extension not on "pathname"
        - there are several IndexedPiece objects
        '''
        test_wm = WorkflowManager([])
        test_wm.settings(None, 'count frequency', False)
        test_wm._result = [mock.MagicMock(spec_set=pandas.DataFrame) for _ in range(5)]
        test_wm._data = ['boop' for _ in range(len(test_wm._result))]
        top_x = None
        threshold = None
        pathname = 'test_path'

        test_wm._make_table('CSV', pathname, top_x, threshold)  # pylint: disable=protected-access
        test_wm._make_table('Excel', pathname, top_x, threshold)  # pylint: disable=protected-access
        test_wm._make_table('Stata', pathname, top_x, threshold)  # pylint: disable=protected-access
        test_wm._make_table('HTML', pathname, top_x, threshold)  # pylint: disable=protected-access

        for i in range(len(test_wm._result)):
            test_wm._result[i].to_csv.assert_called_once_with('{}-{}{}'.format(pathname, i, '.csv'))
            test_wm._result[i].to_excel.assert_called_once_with('{}-{}{}'.format(pathname, i, '.xlsx'))
            test_wm._result[i].to_stata.assert_called_once_with('{}-{}{}'.format(pathname, i, '.dta'))
            test_wm._result[i].to_html.assert_called_once_with('{}-{}{}'.format(pathname, i, '.html'))
예제 #3
0
    def test_lilypond_2(self):
        """one piece with one part; specified pathname; and there's a NaN in the Series!"""
        mock_ips = [MagicMock(spec_set=IndexedPiece)]
        mock_ips[0].get_data.return_value = ['ready for LilyPond']
        result = [pandas.DataFrame({('analyzer', 'clarinet'): pandas.Series(range(10))})]
        result[0][('analyzer', 'clarinet')].iloc[0] = NaN
        exp_series = pandas.Series(range(1, 10), index=range(1, 10))  # to test dropna() was run
        pathname = 'this_path'
        expected = ['this_path.ly']
        exp_get_data_calls = [mock.call([lilypond_ind.AnnotationIndexer,
                                         lilypond_exp.AnnotateTheNoteExperimenter,
                                         lilypond_exp.PartNotesExperimenter],
                                        {'part_names': ['analyzer: clarinet'],
                                         'column': 'lilypond.AnnotationIndexer'},
                                        [mock.ANY]),
                              mock.call([lilypond_exp.LilyPondExperimenter],
                                        {'run_lilypond': True,
                                         'annotation_part': ['ready for LilyPond'],
                                         'output_pathname': expected[0]})]

        test_wm = WorkflowManager(mock_ips)
        test_wm._result = result
        test_wm.settings(None, 'count frequency', False)
        test_wm._make_lilypond(pathname)

        self.assertEqual(2, mock_ips[0].get_data.call_count)
        self.assertSequenceEqual(exp_get_data_calls, mock_ips[0].get_data.call_args_list)
        # check that dropna() was run
        actual_series = mock_ips[0].get_data.call_args_list[0][0][2][0]
        self.assertSequenceEqual(list(exp_series.index), list(actual_series.index))
        self.assertSequenceEqual(list(exp_series.values), list(actual_series.values))
예제 #4
0
 def test_lilypond_1b(self):
     """error conditions: if the lengths are different, (but 'count frequency' is okay)"""
     test_wm = WorkflowManager(['fake piece'])
     test_wm._data = ['fake IndexedPiece']
     test_wm._result = ['fake results', 'more fake results', 'so many fake results']
     test_wm.settings(None, 'count frequency', False)
     with self.assertRaises(RuntimeError) as run_err:
         test_wm._make_lilypond(['paths'])
     self.assertEqual(WorkflowManager._COUNT_FREQUENCY_MESSAGE, run_err.exception.args[0])
예제 #5
0
 def test_output_4(self):
     """ensure RuntimeError if self._result is None"""
     test_wc = WorkflowManager([])
     test_wc._result = None  # just in case
     self.assertRaises(RuntimeError, test_wc.output, 'R histogram')
     try:
         test_wc.output('R histogram')
     except RuntimeError as run_err:
         self.assertEqual(WorkflowManager._NO_RESULTS_ERROR, run_err.args[0])
예제 #6
0
 def test_get_dataframe_4(self):
     # test with name=auto, top_x=5, threshold=7 (so threshold leaves fewer than 3 results)
     test_wc = WorkflowManager([])
     test_wc._result = pandas.Series([i for i in xrange(10, 0, -1)])
     expected = pandas.DataFrame({'data': pandas.Series([10, 9, 8])})
     actual = test_wc._get_dataframe(top_x=5, threshold=7)
     self.assertEqual(len(expected.columns), len(actual.columns))
     for i in expected.columns:
         self.assertSequenceEqual(list(expected.loc[:,i].index), list(actual.loc[:,i].index))
         self.assertSequenceEqual(list(expected.loc[:,i].values), list(actual.loc[:,i].values))
예제 #7
0
 def test_lilypond_1a(self):
     """error conditions: if 'count frequency' is True (but the lengths are okay)"""
     test_wm = WorkflowManager(['fake piece'])
     test_wm._data = ['fake IndexedPiece']
     test_wm._result = ['fake results']
     # test twice like this to make sure (1) the try/except will definitely catch something, and
     # (2) we're not getting hit by another RuntimeError, of which there could be many
     with self.assertRaises(RuntimeError) as run_err:
         test_wm._make_lilypond(['paths'])
     self.assertEqual(WorkflowManager._COUNT_FREQUENCY_MESSAGE, run_err.exception.args[0])
예제 #8
0
 def test_filter_dataframe_3(self):
     """test with top_x=3, threshold=5 (so the top_x still removes after threshold), name=auto"""
     test_wc = WorkflowManager([])
     test_wc._result = pandas.DataFrame({'data': pandas.Series([i for i in range(10, 0, -1)])})
     expected = pandas.DataFrame({'data': pandas.Series([10, 9, 8])})
     actual = test_wc._filter_dataframe(top_x=3, threshold=5)
     self.assertEqual(len(expected.columns), len(actual.columns))
     for i in expected.columns:
         self.assertSequenceEqual(list(expected[i].index), list(actual[i].index))
         self.assertSequenceEqual(list(expected[i].values), list(actual[i].values))
예제 #9
0
 def test_get_dataframe_2(self):
     # test with name='asdf', top_x=3, threshold=auto
     test_wc = WorkflowManager([])
     test_wc._result = pandas.Series([i for i in xrange(10, 0, -1)])
     expected = pandas.DataFrame({'asdf': pandas.Series([10, 9, 8])})
     actual = test_wc._get_dataframe('asdf', 3)
     self.assertEqual(len(expected.columns), len(actual.columns))
     for i in expected.columns:
         self.assertSequenceEqual(list(expected.loc[:,i].index), list(actual.loc[:,i].index))
         self.assertSequenceEqual(list(expected.loc[:,i].values), list(actual.loc[:,i].values))
예제 #10
0
 def test_output_3(self):
     """ensure RuntimeError if there's an invalid instruction"""
     test_wc = WorkflowManager([])
     test_wc._result = [5]  # make sure that's not what causes it
     bad_instruction = 'eat dirt'
     self.assertRaises(RuntimeError, test_wc.output, bad_instruction)
     try:
         test_wc.output(bad_instruction)
     except RuntimeError as run_err:
         self.assertEqual(WorkflowManager._UNRECOGNIZED_INSTRUCTION.format(bad_instruction),
                          run_err.args[0])
예제 #11
0
 def test_lilypond_1b(self):
     # error conditions: if the lengths are different, (but 'count frequency' is okay)
     test_wm = WorkflowManager(['fake piece'])
     test_wm._data = ['fake IndexedPiece']
     test_wm._result = ['fake results', 'more fake results', 'so many fake results']
     test_wm.settings(None, 'count frequency', False)
     self.assertRaises(RuntimeError, test_wm._make_lilypond, ['paths'])
     try:
         test_wm._make_lilypond(['paths'])
     except RuntimeError as the_err:
         self.assertEqual(WorkflowManager._COUNT_FREQUENCY_MESSAGE, the_err.message)
예제 #12
0
 def test_filter_dataframe_5(self):
     """test with top_x=3, threshold=auto, name='asdf'; many input columns"""
     test_wc = WorkflowManager([])
     test_wc._result = pandas.DataFrame({('1', 'b'): pandas.Series([i for i in range(10, 0, -1)]),
                                         ('1', 'z'): pandas.Series([i for i in range(10, 20)]),
                                         ('2', 'e'): pandas.Series([i for i in range(40, 900)])})
     expected = pandas.DataFrame({'asdf': pandas.Series([10, 9, 8])})
     actual = test_wc._filter_dataframe(top_x=3, name='asdf')
     self.assertEqual(len(expected.columns), len(actual.columns))
     for i in expected.columns:
         self.assertSequenceEqual(list(expected[i].index), list(actual[i].index))
         self.assertSequenceEqual(list(expected[i].values), list(actual[i].values))
예제 #13
0
 def test_export_3(self, mock_gdf):
     # --> the method works as expected for CSV, Excel, and Stata when _result is a DataFrame
     test_wm = WorkflowManager([])
     test_wm._result = mock.MagicMock(spec=pandas.DataFrame)
     test_wm.export(u'CSV', u'test_path')
     test_wm.export(u'Excel', u'test_path')
     test_wm.export(u'Stata', u'test_path')
     test_wm.export(u'HTML', u'test_path')
     test_wm._result.to_csv.assert_called_once_with(u'test_path.csv')
     test_wm._result.to_stata.assert_called_once_with(u'test_path.dta')
     test_wm._result.to_excel.assert_called_once_with(u'test_path.xlsx')
     test_wm._result.to_html.assert_called_once_with(u'test_path.html')
     self.assertEqual(0, mock_gdf.call_count)
예제 #14
0
 def test_export_4(self, mock_gdf):
     # --> test_export_3() with a valid extension already on
     test_wm = WorkflowManager([])
     test_wm._result = mock.MagicMock(spec=pandas.DataFrame)
     test_wm.export(u'CSV', u'test_path.csv')
     test_wm.export(u'Excel', u'test_path.xlsx')
     test_wm.export(u'Stata', u'test_path.dta')
     test_wm.export(u'HTML', u'test_path.html')
     test_wm._result.to_csv.assert_called_once_with(u'test_path.csv')
     test_wm._result.to_stata.assert_called_once_with(u'test_path.dta')
     test_wm._result.to_excel.assert_called_once_with(u'test_path.xlsx')
     test_wm._result.to_html.assert_called_once_with(u'test_path.html')
     self.assertEqual(0, mock_gdf.call_count)
예제 #15
0
 def test_histogram_1(self, mock_call, mock_gdf, mock_join):
     # with specified pathname; last experiment was intervals with 20 pieces; self._result is DF
     test_wc = WorkflowManager([])
     test_wc._previous_exp = u'intervals'
     test_wc._data = [1 for _ in xrange(20)]
     test_wc._result = MagicMock(spec=pandas.DataFrame)
     path = u'pathname!'
     actual = test_wc._make_histogram(path)
     self.assertEqual(0, mock_gdf.call_count)
     expected_args = [u'Rscript', u'--vanilla', mock_join.return_value,
                      path + u'.dta', path + u'.png', u'int', u'20']
     mock_call.assert_called_once_with(expected_args)
     self.assertEqual(path + u'.png', actual)
     self.assertEqual(1, mock_join.call_count)
예제 #16
0
 def test_histogram_3(self, mock_call, mock_gdf, mock_join):
     # test_ouput_6, plus top_x and threshold
     test_wc = WorkflowManager([])
     test_wc._previous_exp = u'n-grams'
     test_wc._data = [1]
     test_wc._shared_settings[u'n'] = 14
     test_wc._result = MagicMock(spec=pandas.Series)
     path = u'test_output/output_result'
     actual = test_wc._make_histogram(top_x=420, threshold=1987)
     mock_gdf.assert_called_once_with(u'freq', 420, 1987)
     expected_args = [u'Rscript', u'--vanilla', mock_join.return_value,
                      path + u'.dta', path + u'.png', u'14', u'1']
     mock_call.assert_called_once_with(expected_args)
     self.assertEqual(path + u'.png', actual)
     self.assertEqual(1, mock_join.call_count)
예제 #17
0
 def test_histogram_2(self, mock_call, mock_gdf, mock_join):
     # with unspecified pathname; last experiment was 14-grams with 1 piece; self._result is S
     test_wc = WorkflowManager([])
     test_wc._previous_exp = u'n-grams'
     test_wc._data = [1]
     test_wc._shared_settings[u'n'] = 14
     test_wc._result = MagicMock(spec=pandas.Series)
     path = u'test_output/output_result'
     actual = test_wc._make_histogram()
     mock_gdf.assert_called_once_with(u'freq', None, None)
     expected_args = [u'Rscript', u'--vanilla', mock_join.return_value,
                      path + u'.dta', path + u'.png', u'14', u'1']
     mock_call.assert_called_once_with(expected_args)
     self.assertEqual(path + u'.png', actual)
     self.assertEqual(1, mock_join.call_count)
예제 #18
0
 def test_output_5(self, mock_table):
     """ensure output() calls export() as required"""
     # 1: prepare
     export_path = 'the_path'
     mock_table.return_value = export_path
     test_wc = WorkflowManager([])
     test_wc._previous_exp = 'intervals'
     test_wc._data = [1 for _ in range(20)]
     test_wc._result = MagicMock(spec=pandas.DataFrame)
     path = 'pathname!'
     expected_args = ['Excel', path, None, None]
     # 2: run
     actual = test_wc.output('Excel', path)
     # 3: check
     self.assertEqual(export_path, actual)
     mock_table.assert_called_once_with(*expected_args)
예제 #19
0
 def test_output_2(self, mock_lily):
     # ensure output() calls _make_lilypond() as required
     # 1: prepare
     lily_path = u'the_path'
     mock_lily.return_value = lily_path
     test_wc = WorkflowManager([])
     test_wc._previous_exp = u'intervals'
     test_wc._data = [1 for _ in xrange(20)]
     test_wc._result = MagicMock(spec=pandas.DataFrame)
     path = u'pathname!'
     expected_args = [path]
     # 2: run
     actual = test_wc.output('LilyPond', path)
     # 3: check
     self.assertEqual(lily_path, actual)
     mock_lily.assert_called_once_with(*expected_args)
예제 #20
0
 def test_output_1b(self, mock_histo):
     # ensure output() calls _make_histogram() as required (with 'R histogram' instruction)
     # 1: prepare
     histo_path = u'the_path.svg'
     mock_histo.return_value = histo_path
     test_wc = WorkflowManager([])
     test_wc._previous_exp = u'intervals'
     test_wc._data = [1 for _ in xrange(20)]
     test_wc._result = MagicMock(spec=pandas.DataFrame)
     path = u'pathname!'
     top_x = 20
     threshold = 10
     expected_args = [path, top_x, threshold]
     # 2: run
     actual = test_wc.output('R histogram', path, top_x, threshold)
     # 3: check
     self.assertEqual(histo_path, actual)
     mock_histo.assert_called_once_with(*expected_args)
예제 #21
0
 def test_lilypond_4(self, mock_metadata, test_ip):
     # make sure it works correctly with three pieces that have three parts
     # ("voice combinations" is "all")
     # 1: prepare
     input_path = u'carpathia'
     get_data_ret = lambda *x: ['** ' + str(x[1]) if len(x) == 2 else '** ' + str(x[2][0][-3:])]
     num_parts = 3  # how many parts per piece? -- NB: diffferent from first test
     piece_list = ['test_piece_1.mei', 'test_piece_2.mei', 'test_piece_3.mei']
     test_wm = WorkflowManager(piece_list)
     for i in xrange(len(piece_list)):
         test_wm._data[i] = mock.MagicMock(spec_set=IndexedPiece)
         test_wm._data[i].get_data.side_effect = get_data_ret
     mock_metadata.return_value = ['part %i' % x for x in xrange(num_parts)]
     # the results will be like this: [['fake result 0-0', 'fake result 0-1'],
     #                                 ['fake result 1-0', 'fake result 1-1']]
     exp_results = [['fake result ' + str(i) + '-' + str(j) for j in xrange(num_parts)] \
                    for i in xrange(len(piece_list))]
     test_wm._result = exp_results
     test_wm.settings(None, 'count frequency', False)
     test_wm.settings(0, 'voice combinations', 'all')
     test_wm.settings(1, 'voice combinations', 'all')
     test_wm.settings(2, 'voice combinations', 'all')
     #exp_part_labels = [[[0, 2], [1, 2]] for _ in xrange(len(piece_list))]
     # 2: run
     test_wm._make_lilypond(input_path)
     # 3: check
     self.assertEqual(len(piece_list), test_ip.call_count)  # even though we don't use them
     lily_ind_list = [lilypond.AnnotationIndexer,
                      lilypond.AnnotateTheNoteIndexer,
                      lilypond.PartNotesIndexer]
     for i, piece in enumerate(test_wm._data):
         self.assertEqual(num_parts + 1, piece.get_data.call_count)
         for j in xrange(num_parts):
             piece.get_data.assert_any_call(lily_ind_list,
                                            None,  # {'part_names': exp_part_labels[j]},
                                            [exp_results[i][j]])
         # NB: the output_pathname is different from the previous two tests
         sett_dict = {u'run_lilypond': True,
                     u'output_pathname': input_path + '-' + str(i) + '.ly',
                     u'annotation_part': [get_data_ret(0, 0, [z])[0] for z in exp_results[i]]}
         piece.get_data.assert_any_call([lilypond.LilyPondIndexer], sett_dict)
예제 #22
0
 def test_histogram_4(self, mock_call, mock_gdf, mock_join):
     # test_output_4() but the subprocess thing fails
     def raiser(*args):
         raise CalledProcessError(u'Bach!', 42, u'CPE')
     mock_call.side_effect = raiser
     test_wc = WorkflowManager([])
     test_wc._previous_exp = u'intervals'
     test_wc._data = [1 for _ in xrange(20)]
     test_wc._result = MagicMock(spec=pandas.DataFrame)
     path = u'pathname!'
     expected_msg = u'Error during call to R: CPE (return code: Bach!)'
     actual = None
     try:
         test_wc._make_histogram(path)
     except RuntimeError as run_e:
         actual = run_e
     self.assertEqual(expected_msg, actual.message)
     self.assertEqual(0, mock_gdf.call_count)
     expected_args = [u'Rscript', u'--vanilla', mock_join.return_value,
                      path + u'.dta', path + u'.png', u'int', u'20']
     mock_call.assert_called_once_with(expected_args)
     self.assertEqual(1, mock_join.call_count)
예제 #23
0
 def test_lilypond_2(self, test_ip):
     # make sure it works correctly with one piece that has one part
     # ("voice combinations" with literal_eval())
     # 1: prepare
     input_path = u'carpathia'
     get_data_ret = lambda *x: ['** ' + str(x[1]) if len(x) == 2 else '** ' + str(x[2][0][-3:])]
     num_parts = 1  # how many parts per piece?
     piece_list = ['test_piece.mei']
     test_wm = WorkflowManager(piece_list)
     for i in xrange(len(piece_list)):
         test_wm._data[i] = mock.MagicMock(spec_set=IndexedPiece)
         test_wm._data[i].get_data.side_effect = get_data_ret
     # the results will be like this: [['fake result 0-0', 'fake result 0-1'],
     #                                 ['fake result 1-0', 'fake result 1-1']]
     exp_results = [['fake result ' + str(i) + '-' + str(j) for j in xrange(num_parts)] \
                    for i in xrange(len(piece_list))]
     test_wm._result = exp_results
     test_wm.settings(None, 'count frequency', False)
     test_wm.settings(0, 'voice combinations', '[[0]]')
     #exp_part_labels = [{'part_names': [[0]]}]
     # 2: run
     test_wm._make_lilypond(input_path)
     # 3: check
     self.assertEqual(len(piece_list), test_ip.call_count)  # even though we don't use them
     lily_ind_list = [lilypond.AnnotationIndexer,
                      lilypond.AnnotateTheNoteIndexer,
                      lilypond.PartNotesIndexer]
     for i, piece in enumerate(test_wm._data):
         self.assertEqual(num_parts + 1, piece.get_data.call_count)
         for j in xrange(num_parts):
             piece.get_data.assert_any_call(lily_ind_list,
                                            None,  # {'part_names': exp_part_labels[i]},
                                            [exp_results[i][j]])
         sett_dict = {u'run_lilypond': True,
                      u'output_pathname': input_path + '.ly',
                      u'annotation_part': [get_data_ret(0, 0, [z])[0] for z in exp_results[i]]}
         piece.get_data.assert_any_call([lilypond.LilyPondIndexer], sett_dict)
예제 #24
0
 def test_export_5(self, mock_gdf):
     # --> test_export_3() with a Series that requires calling _get_dataframe()
     test_wm = WorkflowManager([])
     test_wm._result = mock.MagicMock(spec=pandas.Series)
     # CSV
     mock_gdf.return_value = MagicMock(spec=pandas.DataFrame)
     test_wm.export(u'CSV', u'test_path')
     mock_gdf.assert_called_once_with(u'data', None, None)
     mock_gdf.return_value.to_csv.assert_called_once_with(u'test_path.csv')
     mock_gdf.reset_mock()
     # Excel
     test_wm.export(u'Excel', u'test_path', 5)
     mock_gdf.assert_called_once_with(u'data', 5, None)
     mock_gdf.return_value.to_excel.assert_called_once_with(u'test_path.xlsx')
     mock_gdf.reset_mock()
     # Stata
     test_wm.export(u'Stata', u'test_path', 5, 10)
     mock_gdf.assert_called_once_with(u'data', 5, 10)
     mock_gdf.return_value.to_stata.assert_called_once_with(u'test_path.dta')
     mock_gdf.reset_mock()
     # HTML
     test_wm.export(u'HTML', u'test_path', threshold=10)
     mock_gdf.assert_called_once_with(u'data', None, 10)
     mock_gdf.return_value.to_html.assert_called_once_with(u'test_path.html')
예제 #25
0
 def test_output_3(self):
     test_wc = WorkflowManager([])
     test_wc._result = [5]  # make sure that's not what causes it
     self.assertRaises(RuntimeError, test_wc.output, u'LJKDSFLAESFLKJ')
예제 #26
0
    def test_lilypond_3(self):
        """two pieces with two parts; unspecified pathname"""
        mock_ips = [MagicMock(spec_set=IndexedPiece), MagicMock(spec_set=IndexedPiece)]
        mock_ips[0].get_data.return_value = ['0 ready for LilyPond']
        mock_ips[1].get_data.return_value = ['1 ready for LilyPond']
        result = [pandas.DataFrame({('analyzer', 'clarinet'): pandas.Series(range(10)),
                                    ('analyzer', 'tuba'): pandas.Series(range(10))}),
                  pandas.DataFrame({('analyzer', 'flute'): pandas.Series(range(10)),
                                    ('analyzer', 'horn'): pandas.Series(range(10))})]
        expected = ['test_output/output_result-0.ly', 'test_output/output_result-1.ly']
        exp_get_data_calls_0 = [mock.call([lilypond_ind.AnnotationIndexer,
                                           lilypond_exp.AnnotateTheNoteExperimenter,
                                           lilypond_exp.PartNotesExperimenter],
                                          {'part_names': ['analyzer: clarinet'],
                                           'column': 'lilypond.AnnotationIndexer'},
                                          [mock.ANY]),
                                mock.call([lilypond_ind.AnnotationIndexer,
                                           lilypond_exp.AnnotateTheNoteExperimenter,
                                           lilypond_exp.PartNotesExperimenter],
                                          {'part_names': ['analyzer: tuba'],
                                           'column': 'lilypond.AnnotationIndexer'},
                                          [mock.ANY]),
                                mock.call([lilypond_exp.LilyPondExperimenter],
                                          {'run_lilypond': True,
                                           'annotation_part': ['0 ready for LilyPond',
                                                               '0 ready for LilyPond'],
                                           'output_pathname': expected[0]})]
        exp_get_data_calls_1 = [mock.call([lilypond_ind.AnnotationIndexer,
                                           lilypond_exp.AnnotateTheNoteExperimenter,
                                           lilypond_exp.PartNotesExperimenter],
                                          {'part_names': ['analyzer: flute'],
                                           'column': 'lilypond.AnnotationIndexer'},
                                          [mock.ANY]),
                                mock.call([lilypond_ind.AnnotationIndexer,
                                           lilypond_exp.AnnotateTheNoteExperimenter,
                                           lilypond_exp.PartNotesExperimenter],
                                          {'part_names': ['analyzer: horn'],
                                           'column': 'lilypond.AnnotationIndexer'},
                                          [mock.ANY]),
                                mock.call([lilypond_exp.LilyPondExperimenter],
                                          {'run_lilypond': True,
                                           'annotation_part': ['1 ready for LilyPond',
                                                               '1 ready for LilyPond'],
                                           'output_pathname': expected[1]})]

        test_wm = WorkflowManager(mock_ips)
        test_wm._result = result
        test_wm.settings(None, 'count frequency', False)
        test_wm._make_lilypond()

        self.assertEqual(3, mock_ips[0].get_data.call_count)
        self.assertSequenceEqual(exp_get_data_calls_0, mock_ips[0].get_data.call_args_list)
        self.assertEqual(3, mock_ips[1].get_data.call_count)
        self.assertSequenceEqual(exp_get_data_calls_1, mock_ips[1].get_data.call_args_list)
        # check the Series are the ones we expected---this is pretty weird and I'm sorry
        self.assertEqual(result[0][('analyzer', 'clarinet')].name,
                         mock_ips[0].get_data.call_args_list[0][0][2][0].name)
        self.assertEqual(result[0][('analyzer', 'tuba')].name,
                         mock_ips[0].get_data.call_args_list[1][0][2][0].name)
        self.assertEqual(result[1][('analyzer', 'flute')].name,
                         mock_ips[1].get_data.call_args_list[0][0][2][0].name)
        self.assertEqual(result[1][('analyzer', 'horn')].name,
                         mock_ips[1].get_data.call_args_list[1][0][2][0].name)
예제 #27
0
 def test_export_1(self):
     # --> raise RuntimeError with unrecognized output format
     test_wm = WorkflowManager([])
     test_wm._result = pandas.Series(xrange(100))
     self.assertRaises(RuntimeError, test_wm.export, u'PowerPoint')
예제 #28
0
# aggregate results and count frequency, then output that
# NOTE: for this to work, I'll have to prepare ColumnAggregator and FrequencyExperimenter for vis-framework-2.0.0
#print('\nCalculating and outputting aggregated frequencies\n')
#freq_results = the_piece.get_data([aggregator.ColumnAggregator, frequency.FrequencyExperimenter],
                                  #None,
                                  #new_df['dissonance.SuspensionIndexer'])
#freq_results.sort(ascending=False)
#freq_results.to_excel('test_output/aggregated_results.xlsx')

## LilyPond Output! ##
# break a WorkflowManager so we can get annotated score output
print(u'\n\nPreparing and outputting the score, running LilyPond, etc.\n')
# 1.) collect indices for this part combo
#part_diss_orig = dissonances[u'0,1']
#beats_zero_orig = beat_strengths[0]
#beats_one_orig = beat_strengths[1]
# 2.) filter out where there isn't a dissonance
#susp_index = new_df['dissonance.SuspensionIndexer']['0,1']
#part_diss = part_diss_orig[~part_diss_orig.isin([None])]
#beats_zero = beats_zero_orig[~part_diss_orig.isin([None])]
#beats_one = beats_one_orig[~part_diss_orig.isin([None])]
# 3.) mangle the WorkflowManager
workm = WorkflowManager([piece_path])
workm.settings(None, 'voice combinations', '[[0, 1]]')
workm.settings(None, 'count frequency', False)
#workm._result = [new_df['dissonance.SuspensionIndexer']]
#workm._result = [new_df['dissonance.NeighbourNoteIndexer']]
#workm._result = [new_df['dissonance.PassingNoteIndexer']]
workm._result = [combined_df]
workm.output('LilyPond', 'test_output/combined_dissonances')
예제 #29
0
 def test_output_4(self):
     # ensure RuntimeError if self._result is None
     test_wc = WorkflowManager([])
     test_wc._result = None  # just in case
     self.assertRaises(RuntimeError, test_wc.output, u'R histogram')