Exemplo n.º 1
0
def test_setup_logging():
    """
    Ensure that logging is set up in some way.
    """
    with mock.patch('mu.app.TimedRotatingFileHandler') as log_conf, \
            mock.patch('mu.app.os.path.exists', return_value=False),\
            mock.patch('mu.app.logging') as logging, \
            mock.patch('mu.app.os.makedirs', return_value=None) as mkdir:
        setup_logging()
        mkdir.assert_called_once_with(LOG_DIR)
        log_conf.assert_called_once_with(LOG_FILE, when='midnight',
                                         backupCount=5, delay=0)
        logging.getLogger.assert_called_once_with()
        assert sys.excepthook == excepthook
Exemplo n.º 2
0
def test_setup_logging():
    """
    Ensure that logging is set up in some way.
    """
    with mock.patch('mu.app.logging.basicConfig',
                    return_value=None) as log_conf, \
            mock.patch('mu.app.os.path.exists', return_value=False),\
            mock.patch('mu.app.os.makedirs', return_value=None) as mkdir:
        setup_logging()
        mkdir.assert_called_once_with(LOG_DIR)
        log_format = '%(name)s(%(funcName)s) %(levelname)s: %(message)s'
        log_conf.assert_called_once_with(filename=LOG_FILE, filemode='w',
                                         format=log_format,
                                         level=logging.DEBUG)
Exemplo n.º 3
0
def test_setup_logging():
    """
    Ensure that logging is set up in some way.
    """
    with mock.patch('mu.app.TimedRotatingFileHandler') as log_conf, \
            mock.patch('mu.app.os.path.exists', return_value=False),\
            mock.patch('mu.app.logging') as logging, \
            mock.patch('mu.app.os.makedirs', return_value=None) as mkdir:
        setup_logging()
        mkdir.assert_called_once_with(LOG_DIR)
        log_conf.assert_called_once_with(LOG_FILE, when='midnight',
                                         backupCount=5, delay=0)
        logging.getLogger.assert_called_once_with()
        assert sys.excepthook == excepthook
Exemplo n.º 4
0
def test_setup_logging():
    """
    Ensure that logging is set up in some way.
    """
    with mock.patch("mu.app.TimedRotatingFileHandler") as log_conf, mock.patch(
            "mu.app.os.path.exists", return_value=False), mock.patch(
                "mu.app.logging") as logging, mock.patch(
                    "mu.app.os.makedirs", return_value=None) as mkdir:
        setup_logging()
        mkdir.assert_called_once_with(LOG_DIR)
        log_conf.assert_called_once_with(
            LOG_FILE,
            when="midnight",
            backupCount=5,
            delay=0,
            encoding=ENCODING,
        )
        logging.getLogger.assert_called_once_with()
        assert sys.excepthook == excepthook
Exemplo n.º 5
0
def test_setup_logging_with_envvar():
    """
    Ensure that logging is set up in some way.

    Setting the MU_LOG_TO_STDOUT env var ensures that the crash handler
    will not be enabled and stdout logging will
    """
    os.environ["MU_LOG_TO_STDOUT"] = "1"
    with mock.patch("mu.app.TimedRotatingFileHandler") as log_conf, mock.patch(
            "mu.app.os.path.exists", return_value=False), mock.patch(
                "mu.app.logging") as logging, mock.patch(
                    "mu.app.os.makedirs", return_value=None) as mkdir:
        setup_logging()
        mkdir.assert_called_once_with(LOG_DIR)
        log_conf.assert_called_once_with(
            LOG_FILE,
            when="midnight",
            backupCount=5,
            delay=0,
            encoding=ENCODING,
        )
        logging.getLogger.assert_called_once_with()