Ejemplo n.º 1
0
def test_setLevelShowngLogger(loggerLevel, isSuperiorTo, logRecordLevel):
    """
  Set gLogger level: check whether a log record should be displayed
  """
    capturedBackend, log, sublog = gLoggerReset()
    levels = gLogger.getAllPossibleLevels()

    gLogger.setLevel(loggerLevel)

    # convert level name into its integer value
    logRecordLevelValue = LogLevels.getLevelValue(logRecordLevel)
    res = gLogger._createLogRecord(logRecordLevelValue, 'message', '')

    # clean the log to remove unecessary information
    logstring = cleaningLog(capturedBackend.getvalue())

    # if loggerLevel is superior to logRecordLevel then:
    # - log record should not appear
    # - shown should return False as the log doesn't appear
    # - value returned by createLogRecord should be False too
    isLoggerLvlSupToLogRecordLvl = LogLevels.getLevelValue(
        loggerLevel) > logRecordLevelValue
    assert isLoggerLvlSupToLogRecordLvl == isSuperiorTo

    if isLoggerLvlSupToLogRecordLvl:
        assert not gLogger.shown(logRecordLevel)
        assert not res
        assert logstring == ""
    else:
        assert gLogger.shown(logRecordLevel)
        assert res
        assert logstring == "Framework %s: message\n" % logRecordLevel.upper()
        capturedBackend.truncate(0)
        capturedBackend.seek(0)
Ejemplo n.º 2
0
def test_createLogRecord(sMsg, sVarMsg, exc_info, expected):
    """
    Create logs of different levels with multiple logs
    """
    capturedBackend, log, sublog = gLoggerReset()

    # Set the level to debug
    gLogger.setLevel("debug")

    # dictionary of key = logger to use, value = output associated to the logger
    logDict = {gLogger: "", log: "/log", sublog: "/log/sublog"}

    # get list of existing levels, for each of them, a log record is created
    levels = gLogger.getAllPossibleLevels()
    for level in levels:
        for logger, logInfo in logDict.items():

            # createLogRecord is the method in charge of creating the log record
            # debug, ..., always methods wrap the following method
            # we use logLevels to get the int value corresponding to the level name
            logger._createLogRecord(LogLevels.getLevelValue(level), sMsg,
                                    sVarMsg, exc_info)

            # clean the log to remove unecessary information
            logstring = cleaningLog(capturedBackend.getvalue())
            logExpected = "Framework%s %s: %s\n" % (logInfo, level, expected)
            assert logExpected == logstring
            capturedBackend.truncate(0)
            capturedBackend.seek(0)
Ejemplo n.º 3
0
def test_getAllPossibleLevels():
    """
    Make sure getAllPossibleLevels returns every existing level
    """
    _, log, sublog = gLoggerReset()
    levels = ["DEBUG", "VERBOSE", "INFO", "WARN", "NOTICE", "ERROR", "ALWAYS", "FATAL"]
    assert sorted(gLogger.getAllPossibleLevels()) == sorted(levels)
    assert sorted(log.getAllPossibleLevels()) == sorted(levels)
    assert sorted(sublog.getAllPossibleLevels()) == sorted(levels)
Ejemplo n.º 4
0
def test_setLevelgLogger():
    """
  Test setLevel and getLevel: set gLogger level
  """
    _, log, sublog = gLoggerReset()
    levels = gLogger.getAllPossibleLevels()

    # as log and sublog levels has not been changed, they should inherit from the same level
    for level in levels:
        gLogger.setLevel(level)
        assert gLogger.getLevel() == level.upper()
        assert log.getLevel() == level.upper()
        assert sublog.getLevel() == level.upper()
Ejemplo n.º 5
0
def test_setLevelStopPropagation():
    """
  Test setLevel and getLevel: set gLogger level while log and sublog have already be set
  """
    _, log, sublog = gLoggerReset()
    levels = gLogger.getAllPossibleLevels()

    # by changing gLogger level, log and sublog should not be affected anymore as they have been changed manually
    log.setLevel('warn')
    sublog.setLevel('verbose')
    for level in levels:
        gLogger.setLevel(level)
        assert gLogger.getLevel() == level.upper()
        assert log.getLevel() == 'WARN'
        assert sublog.getLevel() == 'VERBOSE'
Ejemplo n.º 6
0
def test_setLevelLog():
    """
  Test setLevel and getLevel: set log level
  """
    _, log, sublog = gLoggerReset()
    levels = gLogger.getAllPossibleLevels()

    # set gLogger level
    gLogger.setLevel('notice')
    # by changing log level, gLogger should not be affected, subLogger should be
    for level in levels:
        log.setLevel(level)
        assert gLogger.getLevel() == 'NOTICE'
        assert log.getLevel() == level.upper()
        assert sublog.getLevel() == level.upper()
Ejemplo n.º 7
0
def test_setLevelSublog():
    """
  Test setLevel and getLevel: set sublog level
  """
    _, log, sublog = gLoggerReset()
    levels = gLogger.getAllPossibleLevels()

    # set gLogger and log level
    gLogger.setLevel('notice')
    log.setLevel('warn')
    # by changing sublog level, gLogger and log should not be affected
    for level in levels:
        sublog.setLevel(level)
        assert gLogger.getLevel() == 'NOTICE'
        assert log.getLevel() == 'WARN'
        assert sublog.getLevel() == level.upper()