How to use the colin.core.loader.CheckLoader function in colin

To help you get started, we’ve selected a few colin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github user-cont / colin / tests / unit / test_loader.py View on Github external
def test_loading_custom_check(tmpdir):
    tests_dir = os.path.dirname(os.path.dirname(__file__))
    a_check_dir = os.path.join(tests_dir, "data", "a_check")
    shutil.copytree(a_check_dir, str(tmpdir.join("a_check")))
    l = CheckLoader([str(tmpdir)])
    assert len(l.check_classes) == 3
    assert l.mapping["a-peter-file-check"]
    assert l.mapping["this-is-a-funky-check"]
github user-cont / colin / tests / unit / test_loader.py View on Github external
def test_import_class():
    l = CheckLoader([])
    check_name = "ArchitectureLabelCheck"
    c = l.import_class("colin.checks.labels.%s" % check_name)
    assert c.name == "architecture_label"
github user-cont / colin / tests / unit / test_loader.py View on Github external
def test_upstream_checks_can_be_loaded():
    """ check whether all upstream checks can be loaded """
    colin_checks_path = colin.checks.__file__
    colin_checks_dir = os.path.dirname(colin_checks_path)
    l = CheckLoader([colin_checks_dir])
    assert l.check_classes
    assert l.mapping["bzcomponent_deprecated"]
    assert l.mapping["architecture_label_capital_deprecated"]
    assert l.mapping["bzcomponent_deprecated"]
    assert l.mapping["install_label_capital_deprecated"]
    assert l.mapping["name_label_capital_deprecated"]
    assert l.mapping["release_label_capital_deprecated"]
    assert l.mapping["uninstall_label_capital_deprecated"]
    assert l.mapping["version_label_capital_deprecated"]
    assert l.mapping["architecture_label"]
    assert l.mapping["authoritative_source-url_label"]
    assert l.mapping["build-date_label"]
    assert l.mapping["com.redhat.build-host_label"]
    assert l.mapping["com.redhat.component_label"]
    assert l.mapping["description_label"]
    assert l.mapping["description_or_io.k8s.description_label"]
github user-cont / colin / colin / core / ruleset / ruleset.py View on Github external
def __init__(self, ruleset_name=None, ruleset_file=None, ruleset=None, checks_paths=None):
        """
        Load ruleset for colin.

        :param ruleset_name: str (name of the ruleset file (without any file extension), default is
                             "default"
        :param ruleset_file: fileobj instance holding ruleset configuration
        :param ruleset: dict, content of a ruleset file
        :param checks_paths: list of str, directories where the checks are present
        """
        self.check_loader = CheckLoader(get_checks_paths(checks_paths))
        if ruleset:
            self.ruleset_struct = RulesetStruct(ruleset)
        elif ruleset_file:
            self.ruleset_struct = get_ruleset_struct_from_fileobj(ruleset_file)
        else:
            logger.debug("Loading ruleset with the name '{}'.".format(ruleset_name))
            ruleset_path = get_ruleset_file(ruleset=ruleset_name)
            self.ruleset_struct = get_ruleset_struct_from_file(ruleset_path)
        if self.ruleset_struct.version not in ["1", 1]:
            raise ColinRulesetException("colin accepts only ruleset version '1'. You provided %r"
                                        % self.ruleset_struct.version)