def test_all_functions_called(self, mock_get_parser, mock_validate_model, mock_validate_file_size): """ Makes sure that all relevant functions are called so that it will parse and validate fully :return: """ # add mock data (as strings) to the function calls that are essential mock_parser_instance = unittest.mock.MagicMock() mock_parser_instance.get_sample_sheet.side_effect = [ "mock_sample_sheet" ] mock_parser_instance.get_sequencing_run.side_effect = [ "mock_sequencing_run" ] mock_get_parser.side_effect = [mock_parser_instance] mock_validation_result = unittest.mock.MagicMock() mock_validation_result.is_valid.side_effect = [True, True] mock_validate_model.side_effect = [mock_validation_result] mock_validate_file_size.side_effect = [mock_validation_result] res = parsing_handler.parse_and_validate("mock_directory") # verify that the functions were called the mock data we set up mock_parser_instance.get_sample_sheet.assert_called_once_with( "mock_directory") mock_parser_instance.get_sequencing_run.assert_called_once_with( "mock_sample_sheet") mock_validate_model.assert_called_once_with("mock_sequencing_run") mock_validate_file_size.assert_called_once_with("mock_sequencing_run") self.assertEqual(res, "mock_sequencing_run")
def run(self): """ This runs when the threads start call is done :return: """ try: status = parsing_handler.get_run_status(self._directory) seq_run = parsing_handler.parse_and_validate(self._directory) if self._parse_as_partial: seq_run = upload_helpers.set_uploaded_samples_to_skip( seq_run, status.get_sample_status_list()) self._run = seq_run except exceptions.DirectoryError as e: # Directory was not valid for some reason full_error = "GUI: ERROR! An error occurred with directory '{}', with message: {}".format( e.directory, e.message) logging.error(full_error) self._error = e.message self._run = None except exceptions.ValidationError as e: # Sequencing Run / SampleSheet was not valid for some reason error_msg = "GUI: ERROR! Errors occurred during validation with message: {}".format( e.message) logging.error(error_msg) error_list_msg = "GUI: Error list: " + pformat( e.validation_result.error_list) logging.error(error_list_msg) full_error = "Error: " + e.message + "\nError List:\n" for err in e.validation_result.error_list: full_error = full_error + str(err) + "\n" self._error = full_error self._run = None except exceptions.SampleSheetError as e: # SampleSheet was not valid for some reason error_msg = "GUI: ERROR! Errors occurred during parsing with message: {}".format( e.message) logging.error(error_msg) self._error = "Errors occurred during parsing `{}` with message: {}".format( e.errors, e.message) self._run = None except exceptions.SequenceFileError as e: # Sequence Files were invalid for some reason full_error = "GUI: ERROR! An error occurred while parsing: {}".format( e.message) logging.error(full_error) self._error = e.message self._run = None except Exception as e: # Some other error occurred full_error = "GUI: ERROR! An unknown error occurred while parsing: {}".format( str(e)) logging.error(full_error) self._error = "ERROR! An error occurred while parsing: {}".format( str(e)) self._run = None pass
def test_invalid_sequencing_run(self, mock_get_parser, mock_validate): """ Check that an exception is thrown when a given SequencingRun is given :return: """ # add mock data (as strings) to the function calls that are essential mock_parser_instance = unittest.mock.MagicMock() mock_parser_instance.get_sample_sheet.side_effect = [ "mock_sample_sheet" ] mock_parser_instance.get_sequencing_run.side_effect = [ "mock_sequencing_run" ] mock_get_parser.side_effect = [mock_parser_instance] mock_validation_result = unittest.mock.MagicMock() mock_validation_result.is_valid.side_effect = [False] mock_validate.side_effect = [mock_validation_result] # make sure the invalid sequencing run raises a ValidationError with self.assertRaises(parsers.exceptions.ValidationError): parsing_handler.parse_and_validate("mock_directory")