Exemplo n.º 1
0
async def test_logging_default_config(dut):
    # The cocotb.log module is shadowed by an instance of
    # cocotb.log.SimBaseLog()
    from cocotb.log import default_config as log_default_config

    cocotb_log = logging.getLogger('cocotb')

    # Save pre-test configuration
    log_level_prev = cocotb_log.level
    os_environ_prev = os.environ.copy()

    try:
        # Set a valid log level
        os.environ['COCOTB_LOG_LEVEL'] = 'DEBUG'
        log_default_config()
        assert cocotb_log.level == logging.DEBUG, cocotb_log.level

        # Try to set log level to an invalid log level
        os.environ['COCOTB_LOG_LEVEL'] = 'INVALID_LOG_LEVEL'
        with assert_raises(ValueError):
            log_default_config()

        # Try to set log level to a valid log level with wrong capitalization
        os.environ['COCOTB_LOG_LEVEL'] = 'error'
        log_default_config()
        assert cocotb_log.level == logging.ERROR, cocotb_log.level

    finally:
        # Restore pre-test configuration
        os.environ = os_environ_prev
        cocotb_log.level = log_level_prev
Exemplo n.º 2
0
async def test_logging_default_config(dut):
    # The cocotb.log module is shadowed by an instance of
    # cocotb.log.SimBaseLog()
    from cocotb.log import default_config as log_default_config

    cocotb_log = logging.getLogger("cocotb")

    # Save pre-test configuration
    log_level_prev = cocotb_log.level
    os_environ_prev = os.environ.copy()

    try:
        # Set a valid log level
        os.environ["COCOTB_LOG_LEVEL"] = "DEBUG"
        log_default_config()
        assert cocotb_log.level == logging.DEBUG, cocotb_log.level

        # Try to set log level to an invalid log level
        os.environ["COCOTB_LOG_LEVEL"] = "INVALID_LOG_LEVEL"
        with pytest.raises(ValueError):
            log_default_config()

        # Try to set log level to a valid log level with wrong capitalization
        os.environ["COCOTB_LOG_LEVEL"] = "error"
        log_default_config()
        assert cocotb_log.level == logging.ERROR, cocotb_log.level

        # Set custom TRACE log level
        os.environ["COCOTB_LOG_LEVEL"] = "TRACE"
        log_default_config()
        assert cocotb_log.level == logging.TRACE, cocotb_log.level

    finally:
        # Restore pre-test configuration
        os.environ = os_environ_prev
        cocotb_log.level = log_level_prev

        logging.getLogger("gpi").setLevel(logging.INFO)