def test_scraper(filename, result_dict, params, evaluate_scraper): """ Test scraper. :filename: Test file name :result_dict: Result dict containing test purpose, and parts of expected results of stdout and stderr :params: schematron file as extra parameter """ correct = parse_results(filename, "text/xml", result_dict, True, params) scraper = SchematronScraper(filename=correct.filename, mimetype="text/xml", params=correct.params) scraper.scrape_file() evaluate_scraper(scraper, correct) if "verbose" in correct.params and correct.params["verbose"]: assert not partial_message_included("have been suppressed", scraper.messages()) elif scraper.messages(): assert partial_message_included("have been suppressed", scraper.messages())
def test_no_wellformed(): """Test scraper without well-formed check.""" scraper = SchematronScraper("tests/data/text_xml/valid_1.0_wellformed.xml", False) scraper.scrape_file() assert partial_message_included("Skipping scraper", scraper.messages()) assert scraper.well_formed is None
def test_scraper(filename, result_dict, params, evaluate_scraper): """Test scraper.""" correct = parse_results(filename, "text/xml", result_dict, True, params) scraper = SchematronScraper(correct.filename, True, correct.params) scraper.scrape_file() correct.version = None correct.streams[0]["version"] = "(:unav)" correct.streams[0]["mimetype"] = "(:unav)" evaluate_scraper(scraper, correct) if "verbose" in correct.params and correct.params["verbose"]: assert not partial_message_included("have been suppressed", scraper.messages()) elif scraper.messages(): assert partial_message_included("have been suppressed", scraper.messages())
def main(arguments=None): """Main loop""" usage = "usage: %prog [options] xml-file-path" parser = optparse.OptionParser(usage=usage) parser.add_option("-s", "--schemapath", dest="schemapath", help="Path to schematron schemas", metavar="PATH") (options, args) = parser.parse_args(arguments) if len(args) != 1: parser.error("Must give a path to an XML file as argument") if options.schemapath is None: parser.error("The -s switch is required") filename = args[0] if os.path.isdir(filename): filename = os.path.join(filename, 'mets.xml') scraper = SchematronScraper( filename, mimetype="text/xml", params={"schematron": options.schemapath}) scraper.scrape_file() message_string = ensure_text(concat(scraper.messages()).strip()) error_string = ensure_text(concat(scraper.errors()).strip()) if message_string: print(message_string) if error_string: print(error_string, file=sys.stderr) if error_string or not scraper.well_formed: return 117 return 0