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
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
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
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))
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
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
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)
def add_result(self, restype, bookpath, linenumber, message): if isinstance(linenumber, int): linenumber = "%d" % linenumber self.results.append( ValidationResult(restype, bookpath, linenumber, "-1", message))
def add_result(self, restype, filename, linenumber, message): self.results.append( ValidationResult(restype, filename, linenumber, message))
# 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