Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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"]
def test_import_class():
l = CheckLoader([])
check_name = "ArchitectureLabelCheck"
c = l.import_class("colin.checks.labels.%s" % check_name)
assert c.name == "architecture_label"
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"]
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)