def test_extract_csv_object_shape(self, mock_to_csv, mock_pbar): '''Test two (object) extractors makes two csv files''' output_file_names = extract_panoptes_csv.extract_csv( self.classification_data_dump_two_tasks, self.config_yaml_two) output_path_T0 = os.path.join(os.getcwd(), 'shape_extractor_point_extractions.csv') output_path_T1 = os.path.join( os.getcwd(), 'shape_extractor_rectangle_extractions.csv') self.assertCountEqual(output_file_names, [output_path_T0, output_path_T1]) if extract_panoptes_csv.flatten_data.return_values[0].task.iloc[ 0] == 'T0': result_dataframe_T0 = extract_panoptes_csv.flatten_data.return_values[ 0] result_dataframe_T1 = extract_panoptes_csv.flatten_data.return_values[ 1] else: result_dataframe_T1 = extract_panoptes_csv.flatten_data.return_values[ 0] result_dataframe_T0 = extract_panoptes_csv.flatten_data.return_values[ 1] assert_frame_equal(result_dataframe_T0, self.extracts_dataframe_two_T0) assert_frame_equal(result_dataframe_T1, self.extracts_dataframe_two_T1) to_csv_calls = [ call(output_path_T0, index=False, encoding='utf-8'), call(output_path_T1, index=False, encoding='utf-8') ] mock_to_csv.assert_has_calls(to_csv_calls, any_order=True)
def test_extract_csv_bad_classification_no_verbose(self, mock_print, mock_to_csv, mock_pbar): '''Test bad classification with verbose off''' output_file_names = extract_panoptes_csv.extract_csv( self.classification_data_dump_one_task, self.config_yaml_fail, verbose=False) mock_print.assert_not_called() self.assertEqual(output_file_names, [])
def test_extract_csv_bad_classification_verbose(self, mock_print, mock_to_csv, mock_pbar): '''Test bad classification with verbose on''' output_file_names = extract_panoptes_csv.extract_csv( self.classification_data_dump_one_task, self.config_yaml_fail, verbose=True) mock_print.assert_any_call('Incorrectly formatted annotation') self.assertEqual(output_file_names, [])
def test_extract_csv_object_n2(self, mock_to_csv, mock_pbar): '''Test one (object) extractor makes one csv file with cpu_count==2''' output_file_names = extract_panoptes_csv.extract_csv( self.classification_data_dump_two_tasks, self.config_yaml_question, cpu_count=2 ) output_path = os.path.join(os.getcwd(), 'question_extractor_extractions.csv') self.assertEqual(output_file_names, [output_path]) mock_to_csv.assert_called_once_with(output_path, index=False, encoding='utf-8')
def test_extract_csv_object(self, mock_to_csv, mock_pbar): '''Test one (object) extractor makes one csv file''' output_file_names = extract_panoptes_csv.extract_csv( self.classification_data_dump_two_tasks, self.config_yaml_question, cpu_count=1 ) output_path = os.path.join(os.getcwd(), 'question_extractor_extractions.csv') self.assertEqual(output_file_names, [output_path]) result_dataframe = extract_panoptes_csv.flatten_data.return_values[0] assert_frame_equal(result_dataframe, self.extracts_dataframe_question, check_like=True) mock_to_csv.assert_called_once_with(output_path, index=False, encoding='utf-8')
def test_extract_csv_list(self, mock_to_csv, mock_pbar): '''Test one (list) extractor makes one csv file''' output_file_names = extract_panoptes_csv.extract_csv( self.classification_data_dump_one_task, self.config_yaml_survey, order=True, cpu_count=1 ) output_path = os.path.join(os.getcwd(), 'survey_extractor_extractions.csv') self.assertEqual(output_file_names, [output_path]) result_dataframe = extract_panoptes_csv.order_columns.return_values[0] assert_frame_equal(result_dataframe, self.extracts_dataframe_survey) mock_to_csv.assert_called_once_with(output_path, index=False, encoding='utf-8')