Пример #1
0
def test_tool_dependencies():
    """Verify that dependencies are reported correctly."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources([os.path.join(os.path.dirname(__file__), 'user_flags_config')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    assert tp.get_tool_dependencies() == []
Пример #2
0
def test_tool_plugin_get_user_flags_invalid_level():
    """Test that we return an empty list for invalid levels."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources([os.path.join(os.path.dirname(__file__), 'user_flags_config')])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    flags = tp.get_user_flags('level2', name='test')
    assert flags == []
Пример #3
0
def test_tool_plugin_load_mapping_missing():
    """Test that we return an empty dict for missing files."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)
    resources = Resources([os.path.join(os.path.dirname(__file__), 'missing_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert not mapping
Пример #4
0
def test_tool_plugin_load_mapping_invalid():
    """Test that we correctly skip invalid entries."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)
    resources = Resources([os.path.join(os.path.dirname(__file__), 'bad_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert not mapping
Пример #5
0
def test_tool_plugin_get_user_flags_valid_flags():
    """Test that we return a list of user flags."""
    arg_parser = argparse.ArgumentParser()
    resources = Resources(
        [os.path.join(os.path.dirname(__file__), "user_flags_config")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    flags = tp.get_user_flags("level", name="test")
    assert flags == ["look", "a", "flag"]
Пример #6
0
def test_tool_plugin_load_mapping_suffixed_fallback():
    """Test that we fall back to the non-suffixed file if we can't find a mapping file with an appropriate suffix."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str, default='gibberish')
    resources = Resources([os.path.join(os.path.dirname(__file__), 'good_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert len(mapping) == 1
    assert mapping == {'a': 'TST1-NO'}
Пример #7
0
def test_tool_plugin_load_mapping_suffixed():
    """Test that we can load the warnings mapping with a suffix."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str, default='experimental')
    resources = Resources([os.path.join(os.path.dirname(__file__), 'good_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert len(mapping) == 1
    assert mapping == {'b': 'TST2-NO'}
Пример #8
0
def test_tool_plugin_load_mapping_valid():
    """Test that we can load the warnings mapping."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--mapping-file-suffix', dest="mapping_file_suffix",
                            type=str)
    arg_parser.add_argument("--output-directory", dest="output_directory")
    resources = Resources([os.path.join(os.path.dirname(__file__), 'good_config')])
    plugin_context = PluginContext(arg_parser.parse_args([]), resources, None)
    tp = ToolPlugin()
    tp.set_plugin_context(plugin_context)
    mapping = tp.load_mapping()
    assert len(mapping) == 1
    assert mapping == {'a': 'TST1-NO'}