# Path: simiki/utils.py
# def color_msg(color, msg):
#     return COLOR_CODES[color] + msg + COLOR_CODES["reset"]
# 
# Path: simiki/log.py
# def logging_init(level=None, logger=getLogger(),
#                  handler=StreamHandler(), use_color=True):
#     if use_color and _is_platform_allowed_ansi():
#         fmt = ANSIFormatter()
#     else:
#         fmt = NonANSIFormatter()
#     handler.setFormatter(fmt)
#     logger.addHandler(handler)
# 
#     if level:
#         logger.setLevel(level)
# 
# Path: simiki/compat.py



import unittest
import logging
import nose
    from cStringIO import StringIO
        from StringIO import StringIO
        from io import StringIO as StringIO
from simiki.utils import color_msg
from simiki.log import logging_init
from simiki.compat import is_py2, unicode
        l2c = {
            "debug": "blue",
            "info": "green",
            "warning": "yellow",
            "error": "red",
            "critical": "bgred"
        }
        for level in l2c:
            # self.handler.flush()
            self.stream.truncate(0)
            # in python 3.x, truncate(0) would not change the current file pos
            # via <http://stackoverflow.com/a/4330829/1276501>
            self.stream.seek(0)
            func = getattr(self.logger, level)
            func(level)
            expected_output = "[{0}]: {1}" \
                .format(color_msg(l2c[level], level.upper()), level)
            stream_output = self.stream.getvalue().strip()
            if is_py2:
                stream_output = unicode(stream_output)
            self.assertEqual(stream_output, expected_output)

    def tearDown(self):
        logging.disable(logging.CRITICAL)
        for handler in self.logger.handlers:
            if not isinstance(handler,
                              nose.plugins.logcapture.MyMemoryHandler):
                self.logger.removeHandler(handler)



# Path: simiki/utils.py
# def color_msg(color, msg):
#     return COLOR_CODES[color] + msg + COLOR_CODES["reset"]
# 
# Path: simiki/log.py
# def logging_init(level=None, logger=getLogger(),
#                  handler=StreamHandler(), use_color=True):
#     if use_color and _is_platform_allowed_ansi():
#         fmt = ANSIFormatter()
#     else:
#         fmt = NonANSIFormatter()
#     handler.setFormatter(fmt)
#     logger.addHandler(handler)
# 
#     if level:
#         logger.setLevel(level)
# 
# Path: simiki/compat.py



# Path: tests/test_log.py
import unittest
import logging
import nose
    from cStringIO import StringIO
        from StringIO import StringIO
        from io import StringIO as StringIO
from simiki.utils import color_msg
from simiki.log import logging_init
from simiki.compat import is_py2, unicode

        l2c = {
            "debug": "blue",
            "info": "green",
            "warning": "yellow",
            "error": "red",
            "critical": "bgred"
        }
        for level in l2c:
            # self.handler.flush()
            self.stream.truncate(0)
            # in python 3.x, truncate(0) would not change the current file pos
            # via <http://stackoverflow.com/a/4330829/1276501>
            self.stream.seek(0)
            func = getattr(self.logger, level)
            func(level)
            expected_output = "[{0}]: {1}" \
                .format(color_msg(l2c[level], level.upper()), level)
            stream_output = self.stream.getvalue().strip()
            if is_py2:
                stream_output = unicode(stream_output)
            self.assertEqual(stream_output, expected_output)

    def tearDown(self):
        logging.disable(logging.CRITICAL)
        for handler in self.logger.handlers:
            if not isinstance(handler,
                              nose.plugins.logcapture.MyMemoryHandler):
                self.logger.removeHandler(handler)



if __name__ == "__main__":