async def test_ignored_without_progress_attribute(self, logger, progress_reporter, error_reporter): logger.critical("Test...") await logger.complete() progress_reporter.assert_not_called() error_reporter.assert_not_called()
async def test_error_no_operation(self, logger, progress_reporter, error_reporter): logger.critical("Test...", progress=50, connector="foo") await logger.complete() progress_reporter.assert_not_called() assert ( "declining request to report progress for record without an operation parameter or inferrable value from event context" in error_reporter.call_args.args[0])
async def test_error_no_connector(self, logger, progress_reporter, error_reporter): logger.critical("Test...", progress=50, connector=None) await logger.complete() progress_reporter.assert_not_called() assert ( "declining request to report progress for record without a connector attribute" in error_reporter.call_args.args[0])
async def test_success_inference_from_context_var(self, logger, progress_reporter, error_reporter): event_context = servo.events.EventContext.from_str("before:measure") with event_context.current(): logger.critical("Test...", progress=50, connector="foo") await logger.complete() progress_reporter.assert_called() error_reporter.assert_not_called()
async def test_success(self, logger, progress_reporter, error_reporter): logger.critical( "Test...", progress=50, connector="foo", operation="hacking", started_at=datetime.now(), ) await logger.complete() progress_reporter.assert_called() error_reporter.assert_not_called()
def test_logging_to_trace(self) -> None: messages = [] logger.add(lambda m: messages.append(m), filter=DEFAULT_FILTER, level=0) set_level("TRACE") logger.critical("critical") logger.debug("debug") logger.trace("trace1") logger.trace("trace2") messages = list(map(lambda m: m.record["message"], messages)) assert messages == ["critical", "debug", "trace1", "trace2"]