Esempio n. 1
0
def test_set_loglevel_correctly():
    """ Test that --loglevel string->const procedure behaves correctly. """
    import logging
    logger = logging.getLogger()
    set_loglevel('debug')
    eq_(logger.isEnabledFor(logging.DEBUG), True)
    set_loglevel('info')
    eq_(logger.isEnabledFor(logging.INFO), True)
    eq_(logger.isEnabledFor(logging.DEBUG), False)
    set_loglevel('warn')
    eq_(logger.isEnabledFor(logging.WARN), True)
    eq_(logger.isEnabledFor(logging.DEBUG), False)
    eq_(logger.isEnabledFor(logging.INFO), False)
    set_loglevel('error')
    eq_(logger.isEnabledFor(logging.ERROR), True)
    eq_(logger.isEnabledFor(logging.WARN), False)
    eq_(logger.isEnabledFor(logging.DEBUG), False)
    eq_(logger.isEnabledFor(logging.INFO), False)
    set_loglevel('debug')
Esempio n. 2
0
def test_set_loglevel_incorrectly():
    """ Test that --loglevel string->const procedure misbehaves correctly. """
    try:
        set_loglevel('invalid')
        assert False, "should have raised assertion"
    except AssertionError as err:
        assert 'not a valid loglevel' in err.args[0], err.args
    try:
        set_loglevel('')
        assert False, "should have raised assertion"
    except AssertionError as err:
        assert 'not a valid loglevel' in err.args[0], err.args
    try:
        set_loglevel(None)
        assert False, "should have raised assertion"
    except AssertionError as err:
        assert err.args[0] is None, err.args[0]