# Path: kibitzr/notifier/factory.py
# class CompositeNotifier(object):
# 
#     REGISTRY = load_notifiers()
# 
#     def __init__(self, conf):
#         self.conf = conf
#         notifiers_conf = conf.get('notify', [])
#         if not notifiers_conf:
#             logger.warning(
#                 "No notifications configured for %r",
#                 conf['name'],
#             )
#         self.notifiers = []
#         for notifier_conf in notifiers_conf:
#             self.add_notifier(notifier_conf)
# 
#     def add_notifier(self, notifier_conf):
#         try:
#             name, value = next(iter(notifier_conf.items()))
#         except AttributeError:
#             name, value = notifier_conf, None
#         try:
#             notify_factory = self.REGISTRY[name]
#         except KeyError:
#             logger.error("Unknown notifier %r", name)
#         else:
#             self.notifiers.append(
#                 notify_factory(conf=self.conf, value=value)
#             )
# 
#     def notify(self, report):
#         if report:
#             logger.debug('Sending report: %r', report)
#             for notifier in self.notifiers:
#                 try:
#                     notifier(report=report)
#                 except:
#                     logger.exception(
#                         "Exception occurred during sending notification"
#                     )
#         else:
#             logger.debug('Report is empty, skipping notification')
#     __call__ = notify
# 
# Path: tests/compat.py

# 
# Path: tests/helpers.py
# class SettingsMock(ReloadableSettings):
# 
#     def __init__(self):
#         self.checks = []
#         self.notifiers = {}
#         self.creds = {'pass': 'password'}
# 
#     @classmethod
#     def instance(cls):
#         ReloadableSettings._instance = cls()
#         return ReloadableSettings._instance
# 
#     @staticmethod
#     def dispose():
#         ReloadableSettings._instance = None


import pytest
from kibitzr.notifier.factory import CompositeNotifier
from ...compat import mock
from ...helpers import SettingsMock




@pytest.fixture()
def settings():
    """Override native settings singleton with empty one"""
    return SettingsMock.instance()


def test_python_unicode_is_handled(settings):
    content = u"\U0001F4A9"
    conf = {
        'notify': [{
            'python': 'conf["content"] = content * 2',
        }],
    }

# Path: kibitzr/notifier/factory.py
# class CompositeNotifier(object):
# 
#     REGISTRY = load_notifiers()
# 
#     def __init__(self, conf):
#         self.conf = conf
#         notifiers_conf = conf.get('notify', [])
#         if not notifiers_conf:
#             logger.warning(
#                 "No notifications configured for %r",
#                 conf['name'],
#             )
#         self.notifiers = []
#         for notifier_conf in notifiers_conf:
#             self.add_notifier(notifier_conf)
# 
#     def add_notifier(self, notifier_conf):
#         try:
#             name, value = next(iter(notifier_conf.items()))
#         except AttributeError:
#             name, value = notifier_conf, None
#         try:
#             notify_factory = self.REGISTRY[name]
#         except KeyError:
#             logger.error("Unknown notifier %r", name)
#         else:
#             self.notifiers.append(
#                 notify_factory(conf=self.conf, value=value)
#             )
# 
#     def notify(self, report):
#         if report:
#             logger.debug('Sending report: %r', report)
#             for notifier in self.notifiers:
#                 try:
#                     notifier(report=report)
#                 except:
#                     logger.exception(
#                         "Exception occurred during sending notification"
#                     )
#         else:
#             logger.debug('Report is empty, skipping notification')
#     __call__ = notify
# 
# Path: tests/compat.py

# 
# Path: tests/helpers.py
# class SettingsMock(ReloadableSettings):
# 
#     def __init__(self):
#         self.checks = []
#         self.notifiers = {}
#         self.creds = {'pass': 'password'}
# 
#     @classmethod
#     def instance(cls):
#         ReloadableSettings._instance = cls()
#         return ReloadableSettings._instance
# 
#     @staticmethod
#     def dispose():
#         ReloadableSettings._instance = None


# Path: tests/unit/notifiers/test_python.py
import pytest
from kibitzr.notifier.factory import CompositeNotifier
from ...compat import mock
from ...helpers import SettingsMock





@pytest.fixture()
def settings():
    """Override native settings singleton with empty one"""
    return SettingsMock.instance()


def test_python_unicode_is_handled(settings):
    content = u"\U0001F4A9"
    conf = {
        'notify': [{
            'python': 'conf["content"] = content * 2',
        }],
    }

    notify_func = CompositeNotifier(conf)