예제 #1
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])
예제 #2
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])
예제 #3
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)
예제 #4
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)
예제 #5
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)
예제 #6
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')