def run_filetype_test(filename, result_dict, filetype, evaluate_scraper, allowed_mimetypes=[]): """ Runs scraper result evaluation for a scraper with forced MIME type/version :filename: Name of the file, not containing the tests/data/mime_type/ part :result_dict: Result dict to be given to Correct :filetype: A dict containing the forced, expected and real file types under the following keys: * given_mimetype: the forced MIME type * given_version: the forced version * expected_mimetype: the expected resulting MIME type * expected_version: the expected resulting version * correct_mimetype: the real MIME type of the file """ correct = force_correct_filetype(filename, result_dict, filetype, allowed_mimetypes) if filetype["given_mimetype"]: mimetype_guess = filetype["given_mimetype"] else: mimetype_guess = filetype["correct_mimetype"] params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"], "mimetype_guess": mimetype_guess } scraper = WandScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forcing_filetype(filename, result_dict, filetype, evaluate_scraper): """Test forcing scraper to use a given MIME type and/or version.""" correct = force_correct_filetype(filename, result_dict, filetype) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"] } scraper = DpxScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(result_dict, filetype, evaluate_scraper): """ Test using user-supplied MIME-types and versions. """ filetype[six.text_type("correct_mimetype")] = "image/png" correct = force_correct_filetype("valid_1.2.png", result_dict, filetype, ["(:unav)"]) params = {"mimetype": filetype["given_mimetype"], "version": filetype["given_version"]} scraper = PngcheckScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(result_dict, filetype, evaluate_scraper): """ Test using user-supplied MIME-types and versions. """ filetype[six.text_type("correct_mimetype")] = "application/pdf" correct = force_correct_filetype("valid_A-1a.pdf", result_dict, filetype) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"] } scraper = VerapdfScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(filename, result_dict, filetype, evaluate_scraper): """ Test using user-supplied MIME-types and versions. """ correct = force_correct_filetype(filename, result_dict, filetype, ["(:unav)"]) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"] } scraper = LxmlScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(result_dict, filetype, evaluate_scraper): """ Test using user-supplied MIME-types and versions. """ filetype[six.text_type("correct_mimetype")] = "text/xml" correct = force_correct_filetype("valid_1.0_well_formed.xml", result_dict, filetype) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"] } scraper = XmllintScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(result_dict, filetype, evaluate_scraper): """ Test using user-supplied MIME-types and versions. """ filetype[six.text_type( "correct_mimetype")] = "application/vnd.oasis.opendocument.spreadsheet" correct = force_correct_filetype("valid_1.1.ods", result_dict, filetype, ["(:unav)"]) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"] } scraper = OfficeScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(result_dict, filetype, evaluate_scraper): """ Test using user-supplied MIME-types and versions. """ filetype[six.text_type("correct_mimetype")] = "text/xml" correct = force_correct_filetype("valid_1.0_well_formed.xml", result_dict, filetype, ["(:unav)"]) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"], "schematron": os.path.join(ROOTPATH, "tests/data/text_xml/local.sch") } scraper = SchematronScraper(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)
def test_forced_filetype(filename, scraper_class, result_dict, filetype, evaluate_scraper): """ Test all JHove scrapers with supported and unsupported forced filetypes. At least forcing the corrext MIME type and version (well-formed), usupported MIME type (not well-formed, the wrong MIME type reported) and forcing only the version (no effect on scraping results) are tested. """ correct = force_correct_filetype(filename, result_dict, filetype) params = { "mimetype": filetype["given_mimetype"], "version": filetype["given_version"] } scraper = scraper_class(correct.filename, True, params) scraper.scrape_file() evaluate_scraper(scraper, correct)