def test_confml_fixer_filter_problems(self):
     fixer = cone.validation.confmlvalidation.FixerBase()
     prbs = [
         api.Problem("msg1", type="test.foo.bar"),
         api.Problem("msg2", type="test.foo.bar"),
         api.Problem("msg3", type="test.foo.faa"),
         api.Problem("msg4", type="test.foo.bar")
     ]
     self.assertEquals(len(fixer.filter_problems(prbs, 'test.foo.bar')), 3)
 def _add_problem(self, setting, msg, prob_type):
     dataobj = setting.datas['data'][-1]
     prob = api.Problem(msg=msg,
                        type=prob_type,
                        line=dataobj.lineno,
                        file=dataobj.get_configuration_path())
     self.context.problems.append(prob)
 def test_create_from_cone_exception_simple(self):
     ex = exceptions.ConeException('foobar')
     self.assertEquals(
         api.Problem.from_exception(ex),
         api.Problem('foobar',
                     type     = '',
                     severity = api.Problem.SEVERITY_ERROR))
 def test_create_from_xml_parse_error(self):
     ex = exceptions.XmlParseError('XML parse error',
                                   problem_lineno = 1)
     self.assertEquals(
         api.Problem.from_exception(ex),
         api.Problem('XML parse error',
                     type     = 'xml',
                     line     = 1,
                     severity = api.Problem.SEVERITY_ERROR))
 def validate(self):
     for dataobj in self.context.configuration._traverse(type=api.Data):
         try:
             self.context.dview.get_feature(dataobj.fqr)
         except exceptions.NotFound:
             prob = api.Problem(msg="Feature '%s' not found" % dataobj.fqr,
                                type=self.PROBLEM_TYPES[0],
                                line=dataobj.lineno,
                                file=dataobj.get_configuration_path())
             self.context.problems.append(prob)
 def validate_setting(self, ref, setting):
     print 'Validating missing desc!'
     if not setting.desc or setting.desc == '':
         prob = api.Problem(msg="Setting/Feature %s: has no description" %
                            (ref),
                            type=self.PROBLEM_TYPES[0],
                            line=setting.lineno,
                            file=setting.get_configuration_path(),
                            severity=api.Problem.SEVERITY_WARNING)
         self.context.problems.append(prob)
 def test_create_from_cone_exception_all_attributes(self):
     ex = exceptions.ConeException('foobar',
                                   problem_lineno = 101,
                                   problem_msg    = 'foobar2',
                                   problem_type   = 'foo.bar')
     self.assertEquals(
         api.Problem.from_exception(ex),
         api.Problem('foobar2',
                     type     = 'foo.bar',
                     line     = 101,
                     severity = api.Problem.SEVERITY_ERROR))
Пример #8
0
    def test_filter_problems(self):
        filter = ProblemTypeFilter(['foo'], ['foo.bar.baz'])
        problems = [
            api.Problem('', type=''),
            api.Problem('', type='foo'),
            api.Problem('', type='bar'),
            api.Problem('', type='foo.bar'),
            api.Problem('', type='foo.bar.baz'),
            api.Problem('', type='foo.bar.baz.x')
        ]

        filtered_problems = filter.filter(problems)
        self.assertEquals(
            filtered_problems,
            [api.Problem('', type='foo'),
             api.Problem('', type='foo.bar')])
    def validate(self):
        for ref, feature in self.context.feature_dict.iteritems():
            if isinstance(feature._obj, model.ConfmlStringSetting
                          ) and feature.ref.startswith('FOO_'):
                value = feature.get_value()
                if isinstance(value, basestring) and 'foo' not in value:
                    dataobj = feature.datas['data'][-1]

                    prob = api.Problem(
                        msg="String 'foo' missing from value of feature '%s'" %
                        ref,
                        type=self.PROBLEM_TYPES[0],
                        line=dataobj.lineno,
                        file=dataobj.get_configuration_path(),
                        severity=api.Problem.SEVERITY_WARNING)
                    self.context.problems.append(prob)
Пример #10
0
 def check_feature_reference(self, ref, line, problem_type):
     """
     Check that a feature with the given reference exists, and if
     not, add a problem.
     
     @param ref: The feature reference to check.
     @param line: The line number to set to the created problem.
     @param line: The problem type to set to the created problem.
     """
     dview = self.context.configuration.get_default_view()
     try:
         dview.get_feature(ref)
     except exceptions.NotFound:
         prob = api.Problem(msg=u"Setting '%s' not found in configuration" %
                            ref,
                            type=problem_type,
                            line=line,
                            file=self.impl.ref)
         self.context.problems.append(prob)
Пример #11
0
 def validate(self):
     # Collect a dictionary of all temporary variable locations,
     # i.e. (file, lineno) tuples
     tempvar_locations_by_ref = {}
     for impl in self.context.all_impls:
         if isinstance(impl, plugin.ImplContainer):
             for td in impl._tempvar_defs:
                 lst = tempvar_locations_by_ref.get(td.ref, [])
                 lst.append((impl.ref, td.lineno))
                 tempvar_locations_by_ref[td.ref] = lst
     
     # Check for duplicates
     for ref, locations in tempvar_locations_by_ref.iteritems():
         if len(locations) > 1:
             for impl_file, lineno in locations:
                 prob = api.Problem(
                     msg = "Duplicate temporary variable ref '%s'" % ref,
                     type = self.PROBLEM_TYPES[0],
                     line = lineno,
                     file = impl_file)
                 self.context.problems.append(prob)
Пример #12
0
    def validate(self):
        for output in self.impl.output_objects:
            encoding = None
            try:
                encoding = utils.expand_refs_by_default_view(
                    output.encoding,
                    self.context.configuration.get_default_view(),
                    catch_not_found=False)
            except exceptions.NotFound:
                # Ignore invalid setting references, they are validated
                # in another validator
                continue

            if encoding is not None:
                # Check the encoding
                try:
                    codecs.lookup(encoding)
                except LookupError:
                    prob = api.Problem(msg=u"Invalid encoding '%s'" % encoding,
                                       type=self.PROBLEM_TYPES[0],
                                       line=output.lineno,
                                       file=self.impl.ref)
                    self.context.problems.append(prob)
Пример #13
0
    def validate(self):
        # Collect a dictionary of CRML keys by UID
        keys_by_uid = {}
        for key in self.impl.repository.keys:
            if isinstance(
                    key,
                (crml_model.CrmlSimpleKey, crml_model.CrmlBitmaskKey)):
                try:
                    try:
                        uid = long(key.int)
                    except ValueError:
                        uid = long(key.int, 16)
                except ValueError:
                    # Silently ignore non-numeric UID values (they should be caught
                    # by other validation)
                    continue
                keys = keys_by_uid.get(uid, [])
                keys.append(key)
                keys_by_uid[uid] = keys

        # Check for duplicates
        for uid, keys in keys_by_uid.iteritems():
            if len(keys) > 1:
                if len(keys) > 2:
                    key_lst = "keys on lines %s" % ', '.join(
                        [str(key.line) for key in keys[:-2]])
                    key_lst += ' and %s' % keys[-2].line
                else:
                    key_lst = "key on line %s" % keys[-2].line
                prob = api.Problem(
                    msg="Duplicate key UID 0x%08X (duplicate with %s)" %
                    (uid, key_lst),
                    type=self.PROBLEM_TYPES[0],
                    line=keys[-1].line,
                    file=self.impl.ref)
                self.context.problems.append(prob)
 def validate(self):
     settings_container = container.DataContainer()
     # Traverse through the configuration model and store each feature to
     # the settings_container.
     for setting in self.context.configuration._traverse(
             type=model.ConfmlFeature):
         settings_container.add_value(setting.fqr, setting)
     # Go though the settings_container to see if any features have more than one
     # definition and report those as problems
     for fqr in settings_container.list_keys():
         if len(settings_container.get_values(fqr)) > 1:
             files = [
                 setting.get_configuration_path()
                 for setting in settings_container.get_values(fqr)
             ]
             prob = api.Problem(
                 msg="Feature %s has '%s' definitions in files %s" %
                 (fqr, len(settings_container.get_values(fqr)), files),
                 type=self.PROBLEM_TYPES[0],
                 severity=api.Problem.SEVERITY_INFO,
                 line=settings_container.get_value(fqr).lineno,
                 file=files[-1],
                 problem_data=settings_container.get_values(fqr))
             self.context.problems.append(prob)
 def test_create_from_generic_exception(self):
     ex = RuntimeError('foobar')
     self.assertEquals(
         api.Problem.from_exception(ex),
         api.Problem('foobar', severity = api.Problem.SEVERITY_ERROR))
def add_parse_warning(msg, line, type='model.confml'):
    parsecontext.get_confml_context().handle_problem(
        api.Problem(msg,
                    severity = api.Problem.SEVERITY_WARNING,
                    type     = type,
                    line     = line))