Skip to content
Snippets Groups Projects
test_logger.py 789 B
Newer Older
  • Learn to ignore specific revisions
  • ulif's avatar
    ulif committed
    import logging
    
    ulif's avatar
    ulif committed
    from diceware.logger import logger, configure
    
    ulif's avatar
    ulif committed
    
    
    def test_logger_exists():
        # the logger does exist
        assert logger is not None
    
    
    def test_logger_has_handler():
        # the logger has at least one handler
        assert len(logger.handlers) > 0
    
    ulif's avatar
    ulif committed
    
    
    def test_get_logger_by_name():
        # we can get a logger directly from std lib
        my_logger = logging.getLogger("ulif.diceware")
        assert len(my_logger.handlers) > 0
    
    ulif's avatar
    ulif committed
    
    
    ulif's avatar
    ulif committed
    
    
    ulif's avatar
    ulif committed
    def test_configure():
        # we can configure the logger.
        my_logger = logging.getLogger("ulif.diceware")
    
        configure(None)
    
    ulif's avatar
    ulif committed
        assert my_logger.level == logging.NOTSET
    
    ulif's avatar
    ulif committed
        configure(0)
    
    ulif's avatar
    ulif committed
        assert my_logger.level == logging.CRITICAL
    
    ulif's avatar
    ulif committed
        configure(1)
        assert my_logger.level == logging.INFO
    
    ulif's avatar
    ulif committed
        configure(2)
        assert my_logger.level == logging.DEBUG