def test_framework_log_output_debug(tmpdir):
    platform_file, config_file = write_basic_config_and_platform_files(tmpdir)

    framework = Framework(config_file_list=[str(config_file)],
                          log_file_name=str(tmpdir.join('framework_log_debug_test.log')),
                          platform_file_name=str(platform_file),
                          debug=True,
                          verbose_debug=False,
                          cmd_nodes=0,
                          cmd_ppn=0)

    framework.log("log message")
    framework.debug("debug message")
    framework.info("info message")
    framework.warning("warning message")
    framework.error("error message")
    try:
        raise ValueError("wrong value")
    except ValueError:
        framework.exception("exception message")
    framework.critical("critical message")

    framework.terminate_all_sims()

    # check output log file
    with open(str(tmpdir.join('framework_log_debug_test.log')), 'r') as f:
        lines = f.readlines()

    assert len(lines) == 32

    assert "Traceback (most recent call last):\n" in lines
    assert '    raise ValueError("wrong value")\n' in lines
    assert "ValueError: wrong value\n" in lines

    # remove timestamp
    lines = [line[24:] for line in lines]

    assert "FRAMEWORK       INFO     log message\n" in lines
    assert "FRAMEWORK       DEBUG    debug message\n" in lines
    assert "FRAMEWORK       INFO     info message\n" in lines
    assert "FRAMEWORK       WARNING  warning message\n" in lines
    assert "FRAMEWORK       ERROR    error message\n" in lines
    assert "FRAMEWORK       ERROR    exception message\n" in lines
    assert "FRAMEWORK       CRITICAL critical message\n" in lines
def test_using_module_components(tmpdir, capfd):
    platform_file, config_file = write_basic_config_and_platform_files(tmpdir)

    framework = Framework(config_file_list=[str(config_file)],
                          log_file_name=str(tmpdir.join('test.log')),
                          platform_file_name=str(platform_file),
                          debug=None,
                          verbose_debug=None,
                          cmd_nodes=0,
                          cmd_ppn=0)

    assert framework.log_file_name.endswith('test.log')

    assert len(framework.config_manager.get_framework_components()) == 2

    component_map = framework.config_manager.get_component_map()

    assert len(component_map) == 1
    assert 'test' in component_map
    test = component_map['test']
    assert len(test) == 1
    assert test[0].get_class_name() == 'HelloDriver'
    assert test[0].get_instance_name().startswith('test@HelloDriver')
    assert test[0].get_serialization().startswith('test@HelloDriver')
    assert test[0].get_sim_name() == 'test'

    # Don't run anything, just check initialization of components
    framework.terminate_all_sims()

    captured = capfd.readouterr()

    captured_out = captured.out.split('\n')
    assert captured_out[0].startswith("Starting IPS")
    assert captured_out[
        1] == "Created <class 'helloworld.hello_driver.HelloDriver'>"
    assert captured_out[
        2] == "Created <class 'helloworld.hello_worker.HelloWorker'>"
    assert captured.err == ''