예제 #1
0
    def validate(self):
        """Iterate over all triples in the graph and validate each one appropriately"""
        errorstring = "Are you calling validate from the base SchemaValidator class?"

        log.info("-" * 100)
        log.info("Validating against %s" % self.schema_def.__class__.__name__)

        if not self.schema_def:
            raise ValueError("No schema definition supplied. %s" % errorstring)

        log.info("in validator.validate: %s" % self.graph)

        # TODO - this should maybe choose the actually used namespace, not just
        # the first one in the list
        result = ValidationResult(self.allowed_namespaces[0])
        if not self.graph:
            return result

        self.checked_attributes = []
        for subject, predicate, object_ in self.graph:
            log.info("")
            log.info("subj: " + subject)
            log.info("pred: " + predicate)
            log.info("obj: " + object_)
            warning = self._check_triple((subject, predicate, object_))
            if warning:
                result.add_error(warning)
        log.info("checked attributes: %s" % self.checked_attributes)
        return result
예제 #2
0
    def validate(self):
        result = ValidationResult("parsely-page")

        if self.data:
            for key in self.data.keys():
                res = self.check_key(key)
                if res:
                    result.append(res)

        return result
예제 #3
0
    def validate(self):
        result = ValidationResult("parsely-page", self.__class__.__name__)

        if self.data:
            for key in self.data.keys():
                res = self.check_key(key)
                if res:
                    result.add_error(res)

        return result
예제 #4
0
 def add_extended_result(self, restype, bookpath, linenumber, charoffset,
                         message):
     if isinstance(linenumber, int):
         linenumber = "%d" % linenumber
     if isinstance(charoffset, int):
         charoffset = "%d" % charoffset
     self.results.append(
         ValidationResult(restype, bookpath, linenumber, charoffset,
                          message))
예제 #5
0
    def validate(self):
        """Iterate over all triples in the graph and validate each one
            appropriately
        """
        log.info("{}\nValidating against {}".format(
            "-" * 100, self.schema_def.__class__.__name__))

        if not self.schema_def:
            raise ValueError("No schema definition supplied.")

        self.checked_attributes = []

        # TODO - this should maybe choose the actually used namespace, not just
        # the first one in the list
        result = ValidationResult(self.allowed_namespaces[0],
                                  self.schema_def.__class__.__name__)
        for subject, predicate, object_ in self.graph:
            log.info("\nsubj: {subj}\npred: {pred}\n obj: {obj}".format(
                subj=subject, pred=predicate, obj=object_.encode('utf-8')))
            result.add_error(self._check_triple((subject, predicate, object_)))
        return result
예제 #6
0
파일: validator.py 프로젝트: bopo/schemato
    def validate(self):
        """Iterate over all triples in the graph and validate each one
            appropriately
        """
        log.info("{}\nValidating against {}"
                 .format("-" * 100, self.schema_def.__class__.__name__))

        if not self.schema_def:
            raise ValueError("No schema definition supplied.")

        self.checked_attributes = []

        # TODO - this should maybe choose the actually used namespace, not just
        # the first one in the list
        result = ValidationResult(self.allowed_namespaces[0],
                                  self.schema_def.__class__.__name__)
        for subject, predicate, object_ in self.graph:
            log.info("\nsubj: {subj}\npred: {pred}\n obj: {obj}"
                     .format(subj=subject, pred=predicate,
                             obj=object_.encode('utf-8')))
            result.add_error(self._check_triple((subject, predicate, object_)))
        return result
예제 #7
0
    def validate_XML_by_path(self, xml_path, schema_path):
        """
        This function validates the XML meta data file (parsed_mfile) describing the SIP against the .xsd (sfile),
        which is either contained in the SIP or referenced in the .xml

        @type       xml_path: string
        @param      xml_path: Path to XML file
        @type       schema_path:  string
        @param      schema_path:  Path to schema file.
        @rtype:     ValidationResult
        @return:    Validation result (valid: true/false, processing log, error log)
        """
        validationResult = ValidationResult(False, [], [])
        try:
            parsed_schema = lxml.etree.parse(schema_path)
            parsed_xml = lxml.etree.parse(xml_path)
            validationResult = self.validate_XML(parsed_xml, parsed_schema)
        except lxml.etree.XMLSchemaParseError, xspe:
            # Something wrong with the schema (getting from URL/parsing)
            validationResult.err.append("XMLSchemaParseError occurred!")
            validationResult.err.append(xspe)
예제 #8
0
 def add_result(self, restype, bookpath, linenumber, message):
     if isinstance(linenumber, int):
         linenumber = "%d" % linenumber
     self.results.append(
         ValidationResult(restype, bookpath, linenumber, "-1", message))
예제 #9
0
 def add_result(self, restype, filename, linenumber, message):
     self.results.append(
         ValidationResult(restype, filename, linenumber, message))
예제 #10
0
            # XML failed to validate against schema
            err.append("DocumentInvalid occurred!")
            error = schema.error_log.last_error
            if error:
                # All the error properties (from libxml2) describing what went wrong
                err.append('domain_name: ' + error.domain_name)
                err.append('domain: ' + str(error.domain))
                err.append('filename: ' + error.filename)  # '<string>' cos var is a string of xml
                err.append('level: ' + str(error.level))
                err.append('level_name: ' + error.level_name)  # an integer
                err.append('line: ' + str(error.line))  # a unicode string that identifies the line where the error occurred.
                err.append('message: ' + error.message)  # a unicode string that lists the message.
                err.append('type: ' + str(error.type))  # an integer
                err.append('type_name: ' + error.type_name)
        finally:
            return ValidationResult(valid_xml, log, err)

class TestXmlValidation(unittest.TestCase):

    test_directory = root_dir + '/earkcore/xml/resources/'
    schema_file = test_directory + 'schema.xsd'
    #print schema_file

    xmlval = XmlValidation()

    def test_validate_valid(self):
        """
        Must return valid for a valid XML
        """
        xml_file = self.test_directory + 'instance.xml'
        print xml_file