Example #1
0
    def testFieldsUniverseGetFindings(self):
        context = findings_lib.FileContext(_GOOD_PATH + '/file.yaml')
        folder = field_lib.FieldFolder(_GOOD_PATH)
        folder.AddFinding(
            findings_lib.InconsistentFileLocationError('', context))
        namespace = folder.local_namespace
        namespace.AddFinding(
            findings_lib.UnrecognizedSubfieldError(['any'],
                                                   field_lib.Field(
                                                       'two',
                                                       file_context=context)))
        field = field_lib.Field('one', file_context=context)
        # Currently there are no warnings for fields, so using a subfield warning
        field.AddFinding(
            findings_lib.MissingSubfieldDescriptionWarning('one', context))
        namespace.InsertField(field)

        fields_universe = field_lib.FieldUniverse([folder])

        findings = fields_universe.GetFindings()
        self.assertLen(findings, 3)
        self.assertTrue(
            fields_universe.HasFindingTypes([
                findings_lib.InconsistentFileLocationError,
                findings_lib.UnrecognizedSubfieldError,
                findings_lib.MissingSubfieldDescriptionWarning
            ]))
        self.assertFalse(fields_universe.IsValid())
Example #2
0
    def testSubfieldUniverseGetFindings(self):
        context = findings_lib.FileContext(_GOOD_PATH + '/file.yaml')
        folder = subfield_lib.SubfieldFolder(_GOOD_PATH)
        folder.AddFinding(
            findings_lib.InconsistentFileLocationError('', context))
        namespace = folder.local_namespace
        namespace.AddFinding(
            findings_lib.DuplicateSubfieldDefinitionError(
                namespace,
                subfield_lib.Subfield(
                    'two', subfield_lib.SubfieldCategory.POINT_TYPE), context))
        subfield_one = subfield_lib.Subfield(
            'one', subfield_lib.SubfieldCategory.POINT_TYPE, 'thing')
        subfield_one.AddFinding(
            findings_lib.MissingSubfieldDescriptionWarning('one', context))
        namespace.InsertSubfield(subfield_one)

        subfields_universe = subfield_lib.SubfieldUniverse([folder])

        findings = subfields_universe.GetFindings()
        self.assertLen(findings, 3)
        self.assertTrue(
            subfields_universe.HasFindingTypes([
                findings_lib.InconsistentFileLocationError,
                findings_lib.DuplicateSubfieldDefinitionError,
                findings_lib.MissingSubfieldDescriptionWarning
            ]))
        self.assertFalse(subfields_universe.IsValid())
Example #3
0
    def __init__(self, name, category, description=None, context=None):
        super(Subfield, self).__init__()
        self.context = context
        self.name = name
        self.description = description
        self.category = category

        if not isinstance(name, str):
            self.AddFinding(findings_lib.IllegalKeyTypeError(name, context))
        elif not _SUBFIELD_NAME_VALIDATOR.match(name):
            self.AddFinding(findings_lib.IllegalCharacterError(name, context))
        if not self.description:
            self.AddFinding(
                findings_lib.MissingSubfieldDescriptionWarning(
                    self.name, self.context))