def test_warning_setsWarningOccurred(self): args = Namespace(log_file="test.log", verbose=True) console_stream = StringIO() logger = utils.Logger(args, console_stream) logger._file_logger = MockBaseLogger() self.assertEqual(False, logger.warning_occurred) logger.warning("oops") self.assertEqual(True, logger.warning_occurred)
def test_consoleFormat(self): args = Namespace(log_file="test.log", verbose=None) console_stream = StringIO() logger = utils.Logger(args, console_stream) logger._file_logger = MockBaseLogger() logger.info("info [{}]", "i") console_lines = console_stream.getvalue().strip().split("\n") self.assertEqual(1, len(console_lines)) fields = console_lines[0].split("|") self.assertEqual(3, len(fields)) self.assertEqual(fields[1], "INFO") self.assertEqual(fields[2], "info [i]")
def main(command_line_args=None): '''Connor entry point. See help for more info''' log = None if not command_line_args: command_line_args = sys.argv try: start_time = time.time() args = _parse_command_line_args(command_line_args) log = utils.Logger(args) command_validator.preflight(args, log) log.info('connor begins (v{})', __version__) log.info('logging to [{}]', args.log_file) utils.log_environment_info(log, args) bam_tags = samtools._build_bam_tags() base_annotated_writer = samtools.build_writer(args.input_bam, args.annotated_output_bam, bam_tags, args) annotated_writer = LoggingWriter(base_annotated_writer, log) consensus_writer = samtools.build_writer(args.input_bam, args.output_bam, bam_tags, args) _dedup_alignments(args, consensus_writer, annotated_writer, log) annotated_writer.close(log) consensus_writer.close(log) warning = ' **See warnings above**' if log.warning_occurred else '' elapsed_time = int(time.time() - start_time) log.info("connor complete ({} seconds, {}mb peak memory).{}", elapsed_time, utils.peak_memory(), warning) except utils.UsageError as usage_error: message = "connor usage problem: {}".format(str(usage_error)) print(message, file=sys.stderr) print("See 'connor --help'.", file=sys.stderr) sys.exit(1) except Exception: #pylint: disable=broad-except if log: show = log.error else: show = partial(print, file=sys.stderr) show("An unexpected error occurred") show(traceback.format_exc()) exit(1)
def test_notVerbose(self): args = Namespace(log_file="test.log", verbose=None) console_stream = StringIO() file_logger = MockBaseLogger() logger = utils.Logger(args, console_stream) logger._file_logger = file_logger logger.debug("debug [{}]", "d") logger.info("info [{}]", "i") logger.warning("warning [{}]", "w") logger.error("error [{}]", "e") console_lines = console_stream.getvalue().strip().split("\n") self.assertEqual(3, len(console_lines)) console_lines[0].endswith("info [i]") console_lines[1].endswith("warning [w]") console_lines[2].endswith("error [e]") self.assertEqual(4, len(file_logger.lines)) file_logger.lines[0].endswith("debug [d]") file_logger.lines[1].endswith("info [i]") file_logger.lines[2].endswith("warning [w]") file_logger.lines[3].endswith("error [e]")