def test_no_wellformed(): """Test scraper without well-formed check.""" scraper = XmllintScraper("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_parameters(): """Test that parameters and default values work properly.""" # pylint: disable=protected-access scraper = XmllintScraper("testsfile", "test/mimetype") assert scraper._schema is None assert scraper._catalogs assert scraper._no_network assert scraper._catalog_path is None scraper = XmllintScraper(filename="testsfile", mimetype="text/xml", params={ "schema": "schemafile", "catalogs": False, "no_network": False }) assert scraper._schema == "schemafile" assert not scraper._catalogs assert not scraper._no_network scraper = XmllintScraper(filename="testsfile", mimetype="text/xml", params={"catalog_path": "catpath"}) assert scraper._catalogs assert scraper._catalog_path == "catpath"
def test_is_supported(): """Test is_supported method.""" mime = "text/xml" ver = "1.0" assert XmllintScraper.is_supported(mime, ver, True) assert XmllintScraper.is_supported(mime, None, True) assert not XmllintScraper.is_supported(mime, ver, False) assert XmllintScraper.is_supported(mime, "foo", True) assert not XmllintScraper.is_supported("foo", ver, True)
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_scraper_invalid(filename, result_dict, params, evaluate_scraper): """ Test scraper with invalid files. :filename: Test file name :result_dict: Result dict containing test purpose, and parts of expected results of stdout and stderr :params: Extra parameters for Scraper """ correct = parse_results(filename, "text/xml", result_dict, True, params) scraper = XmllintScraper(filename=correct.filename, mimetype="text/xml", params=correct.params) scraper.scrape_file() if any(item in filename for item in ["empty", "no_closing_tag", "no_namespace_catalog", "diacritics"]): correct.well_formed = False correct.version = None correct.streams[0]["version"] = None if not correct.well_formed: assert not scraper.well_formed assert not scraper.streams assert partial_message_included(correct.stdout_part, scraper.messages()) assert partial_message_included(correct.stderr_part, scraper.errors()) else: evaluate_scraper(scraper, correct) assert not partial_message_included("<note>", scraper.messages())
def test_scraper_valid(filename, result_dict, params, evaluate_scraper): """Test scraper.""" correct = parse_results(filename, "text/xml", result_dict, True, params) scraper = XmllintScraper(correct.filename, True, correct.params) scraper.scrape_file() if not correct.well_formed: assert not scraper.well_formed assert not scraper.streams assert partial_message_included(correct.stdout_part, scraper.messages()) assert partial_message_included(correct.stderr_part, scraper.errors()) else: evaluate_scraper(scraper, correct) assert not partial_message_included("<note>", scraper.messages())
def test_scraper_invalid(filename, result_dict, params, evaluate_scraper): """Test scraper.""" correct = parse_results(filename, "text/xml", result_dict, True, params) scraper = XmllintScraper(correct.filename, True, correct.params) scraper.scrape_file() if "empty" in filename or "no_closing_tag" in filename: correct.version = None correct.streams[0]["version"] = None if not correct.well_formed: assert not scraper.well_formed assert not scraper.streams assert partial_message_included(correct.stdout_part, scraper.messages()) assert partial_message_included(correct.stderr_part, scraper.errors()) else: evaluate_scraper(scraper, correct) assert not partial_message_included("<note>", scraper.messages())
def test_scraper_valid(filename, result_dict, params, evaluate_scraper): """ Test scraper with valid files. :filename: Test file name :result_dict: Result dict containing test purpose, and parts of expected results of stdout and stderr :params: Extra parameters for Scraper """ correct = parse_results(filename, "text/xml", result_dict, True, params) scraper = XmllintScraper(filename=correct.filename, mimetype="text/xml", params=correct.params) scraper.scrape_file() if not correct.well_formed: assert not scraper.well_formed assert not scraper.streams assert partial_message_included(correct.stdout_part, scraper.messages()) assert partial_message_included(correct.stderr_part, scraper.errors()) else: evaluate_scraper(scraper, correct) assert not partial_message_included("<note>", scraper.messages())