# Path: kwiklib/utils/logger.py
# class StringLogger(Logger):
#     def __init__(self, **kwargs):
#         kwargs['stream'] = StringStream()
#         super(StringLogger, self).__init__(**kwargs)
#         
#     def __repr__(self):
#         return self.stream.__repr__()
# 
# class ConsoleLogger(Logger):
#     def __init__(self, **kwargs):
#         kwargs['stream'] = sys.stdout
#         super(ConsoleLogger, self).__init__(**kwargs)
# 
# class StringStream(object):
#     """Logger stream used to store all logs in a string."""
#     def __init__(self):
#         self.string = ""
#         
#     def write(self, line):
#         self.string += line
#         
#     def flush(self):
#         pass
#         
#     def __repr__(self):
#         return self.string
# 
# class FileLogger(Logger):
#     def __init__(self, filename=None, **kwargs):
#         kwargs['handler'] = logging.FileHandler(filename)
#         super(FileLogger, self).__init__(**kwargs)
#         
#     def close(self):
#         self.handler.close()
#         self._logger.removeHandler(self.handler)
#         del self.handler
#         del self._logger
# 
# def register(logger):
#     name = logger.name
#     if name not in LOGGERS:
#         LOGGERS[name] = logger


import sys
import os
import logging
from kwiklib.utils.logger import (StringLogger, ConsoleLogger,
    StringStream, FileLogger, register)
"""Unit tests for logger module."""

# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------



# -----------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------
def test_string_logger():
    l = StringLogger(fmt='')
    l.info("test 1")
    l.info("test 2")
    
    log = str(l)
    logs = log.split('\n')

    assert "test 1" in logs[0]
    assert "test 2" in logs[1]
    
def test_console_logger():
    l = ConsoleLogger(fmt='')
    l.info("test 1")
    l.info("test 2")
    
def test_file_logger():
    logfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                'log.txt')

# Path: kwiklib/utils/logger.py
# class StringLogger(Logger):
#     def __init__(self, **kwargs):
#         kwargs['stream'] = StringStream()
#         super(StringLogger, self).__init__(**kwargs)
#         
#     def __repr__(self):
#         return self.stream.__repr__()
# 
# class ConsoleLogger(Logger):
#     def __init__(self, **kwargs):
#         kwargs['stream'] = sys.stdout
#         super(ConsoleLogger, self).__init__(**kwargs)
# 
# class StringStream(object):
#     """Logger stream used to store all logs in a string."""
#     def __init__(self):
#         self.string = ""
#         
#     def write(self, line):
#         self.string += line
#         
#     def flush(self):
#         pass
#         
#     def __repr__(self):
#         return self.string
# 
# class FileLogger(Logger):
#     def __init__(self, filename=None, **kwargs):
#         kwargs['handler'] = logging.FileHandler(filename)
#         super(FileLogger, self).__init__(**kwargs)
#         
#     def close(self):
#         self.handler.close()
#         self._logger.removeHandler(self.handler)
#         del self.handler
#         del self._logger
# 
# def register(logger):
#     name = logger.name
#     if name not in LOGGERS:
#         LOGGERS[name] = logger


# Path: kwiklib/utils/tests/test_logger.py
import sys
import os
import logging
from kwiklib.utils.logger import (StringLogger, ConsoleLogger,
    StringStream, FileLogger, register)

"""Unit tests for logger module."""

# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------



# -----------------------------------------------------------------------------
# Tests
# -----------------------------------------------------------------------------
def test_string_logger():
    l = StringLogger(fmt='')
    l.info("test 1")
    l.info("test 2")
    
    log = str(l)
    logs = log.split('\n')

    assert "test 1" in logs[0]
    assert "test 2" in logs[1]
    
def test_console_logger():
    l = ConsoleLogger(fmt='')
    l.info("test 1")
    l.info("test 2")
    
def test_file_logger():
    logfile = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                'log.txt')

    l = FileLogger(logfile, fmt='', level=logging.DEBUG, print_caller=False)