def test_push_works_As_expected(self): sender = MockAsynchronousSender() queue = channel.AsynchronousQueue(sender) queue.put(42) self.assertEqual(1, sender.start_call_count) self.assertEqual(42, queue.get()) self.assertIsNone(queue.get())
def test_flush_works_as_expected(self): sender = MockAsynchronousSender() queue = channel.AsynchronousQueue(sender) self.assertIsNotNone(queue.flush_notification) result = queue.flush_notification.wait(1) self.assertEqual(False, result) queue.flush() self.assertEqual(1, sender.start_call_count) result = queue.flush_notification.wait() self.assertEqual(True, result)
def test_flush_notification_works_as_expected(self): queue = channel.AsynchronousQueue(MockAsynchronousSender()) self.assertIsNotNone(queue.flush_notification) result = queue.flush_notification.wait(1) self.assertEqual(False, result) queue.flush_notification.set() result = queue.flush_notification.wait() self.assertEqual(True, result) queue.flush_notification.clear() result = queue.flush_notification.wait(1) self.assertEqual(False, result)
def test_with_null_sender(self): sender = channel.NullSender() queue = channel.AsynchronousQueue(sender) queue.put(1) queue.put(2) queue.flush()
def test_construct(self): queue = channel.AsynchronousQueue(MockAsynchronousSender()) self.assertIsNotNone(queue.flush_notification)
def start_logger() -> None: """ Start logging of messages passed through the python logging module. This sets up logging to a time based logging. This means that all logging messages on or above ``filelogginglevel`` will be written to `pythonlog.log` All logging messages on or above ``consolelogginglevel`` will be written to stderr. ``filelogginglevel`` and ``consolelogginglevel`` are defined in the ``qcodesrc.json`` file. """ global console_handler global file_handler # set loggers to the supplied levels for name, level in qc.config.logger.logger_levels.items(): logging.getLogger(name).setLevel(level) root_logger = logging.getLogger() root_logger.setLevel(logging.DEBUG) # remove previously set handlers for handler in (console_handler, file_handler): if handler is not None: handler.close() root_logger.removeHandler(handler) # add qcodes handlers # console console_handler = logging.StreamHandler() console_handler.setLevel(qc.config.logger.console_level) console_handler.setFormatter(get_formatter()) root_logger.addHandler(console_handler) # file filename = get_log_file_name() os.makedirs(os.path.dirname(filename), exist_ok=True) file_handler = logging.handlers.TimedRotatingFileHandler(filename, when='midnight') file_handler.setLevel(qc.config.logger.file_level) file_handler.setFormatter(get_formatter()) root_logger.addHandler(file_handler) # capture any warnings from the warnings module logging.captureWarnings(capture=True) if qc.config.telemetry.enabled: from applicationinsights import channel from applicationinsights.logging import enable # the telemetry_handler can be flushed global telemetry_handler loc = qc.config.GUID_components.location stat = qc.config.GUID_components.work_station sender = channel.AsynchronousSender() queue = channel.AsynchronousQueue(sender) appin_channel = channel.TelemetryChannel(context=None, queue=queue) appin_channel.context.user.id = f'{loc:02x}-{stat:06x}' # it is not completely clear which context fields get sent up. # Here we shuffle some info from one field to another. acc_name = appin_channel.context.device.id appin_channel.context.user.account_id = acc_name # note that the following function will simply silently fail if an # invalid instrumentation key is used. There is thus no exception to # catch telemetry_handler = enable(qc.config.telemetry.instrumentation_key, telemetry_channel=appin_channel) log.info("QCoDes logger setup completed") log_qcodes_versions(log) print(f'Qcodes Logfile : {filename}')