def test_log_infos_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that the callbacks are registered properly"""

        plugin.register_plugin(collectd=collectd)

        # When log messages are produced
        ROOT_LOGGER.info('%d info', 1)

        # When plugin function is called
        collectd.info.assert_called_once_with('1 info')
    def test_log_fatal_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that the callbacks are registered properly"""

        plugin.register_plugin(collectd=collectd)

        # When log messages are produced
        ROOT_LOGGER.fatal('some error')

        # When plugin function is called
        collectd.error.assert_called_once_with('some error')
    def test_log_fatal_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that the callbacks are registered properly"""

        plugin.register_plugin(collectd=collectd)

        # When log messages are produced
        ROOT_LOGGER.fatal('some error')

        # When plugin function is called
        collectd.error.assert_called_once_with('some error')
    def test_log_debug_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that debug messages are sent to collectd."""

        plugin.register_plugin(collectd=collectd)

        # When log messages are produced
        ROOT_LOGGER.debug('some %s', 'noise')

        # When plugin function is called
        collectd.debug.assert_called_once_with('some noise')
    def test_log_infos_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that the callbacks are registered properly"""

        plugin.register_plugin(collectd=collectd)

        # When log messages are produced
        ROOT_LOGGER.info('%d info', 1)

        # When plugin function is called
        collectd.info.assert_called_once_with('1 info')
    def test_log_debug_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that debug messages are sent to collectd."""

        plugin.register_plugin(collectd=collectd)

        # When log messages are produced
        ROOT_LOGGER.debug('some %s', 'noise')

        # When plugin function is called
        collectd.debug.assert_called_once_with('some noise')
    def test_log_exceptions_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that the callbacks are registered properly"""

        plugin.register_plugin(collectd=collectd)

        # When exception is logged
        try:
            raise ValueError('some error')
        except ValueError:
            ROOT_LOGGER.exception('got exception')

        # When main function is called
        collectd.error.assert_called_once_with(
            match.wildcard('got exception\n'
                           'Traceback (most recent call last):\n'
                           '*'
                           'ValueError: some error'))
    def test_log_exceptions_to_collectd(self, collectd, ROOT_LOGGER):
        """Verify that the callbacks are registered properly"""

        plugin.register_plugin(collectd=collectd)

        # When exception is logged
        try:
            raise ValueError('some error')
        except ValueError:
            ROOT_LOGGER.exception('got exception')

        # When main function is called
        collectd.error.assert_called_once_with(
            match.wildcard('got exception\n'
                           'Traceback (most recent call last):\n'
                           '*'
                           'ValueError: some error'))
    def test_callbacks(self, collectd, ROOT_LOGGER, CollectdLogHandler, Config,
                       Plugin):
        """Verify that the callbacks are registered properly"""

        # When plugin function is called
        plugin.register_plugin(collectd=collectd)

        # Logger handler is set up
        ROOT_LOGGER.addHandler.assert_called_once_with(
            CollectdLogHandler.return_value)
        ROOT_LOGGER.setLevel.assert_called_once_with(logging.NOTSET)

        # It create a plugin
        Plugin.assert_called_once_with(collectd=collectd,
                                       config=Config.instance.return_value)

        # callbacks are registered to collectd
        instance = Plugin.return_value
        collectd.register_config.assert_called_once_with(instance.config)
        collectd.register_write.assert_called_once_with(instance.write)
        collectd.register_shutdown.assert_called_once_with(instance.shutdown)
    def test_callbacks(
            self, collectd, ROOT_LOGGER, CollectdLogHandler, Config, Plugin):
        """Verify that the callbacks are registered properly"""

        # When plugin function is called
        plugin.register_plugin(collectd=collectd)

        # Logger handler is set up
        ROOT_LOGGER.addHandler.assert_called_once_with(
            CollectdLogHandler.return_value)
        ROOT_LOGGER.setLevel.assert_called_once_with(logging.NOTSET)

        # It create a plugin
        Plugin.assert_called_once_with(
            collectd=collectd, config=Config.instance.return_value)

        # callbacks are registered to collectd
        instance = Plugin.return_value
        collectd.register_config.assert_called_once_with(instance.config)
        collectd.register_write.assert_called_once_with(instance.write)
        collectd.register_shutdown.assert_called_once_with(instance.shutdown)