diff options
author | Leonard Richardson <leonardr@segfault.org> | 2021-10-24 21:16:08 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2021-10-24 21:16:08 -0400 |
commit | c005e9ba28b4eec3a5fab173b928609bc692dd51 (patch) | |
tree | 0d53e5aa5d1f82b4b3dd77a9fbf73086e30a31d2 | |
parent | c1a7aaae7140897b2e845be8c5aa077d6654ee0a (diff) |
Added test of warn_if_markup_looks_like_xml.
-rw-r--r-- | bs4/tests/test_builder.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bs4/tests/test_builder.py b/bs4/tests/test_builder.py new file mode 100644 index 0000000..7537071 --- /dev/null +++ b/bs4/tests/test_builder.py @@ -0,0 +1,29 @@ +import pytest +from unittest.mock import patch +from bs4.builder import DetectsXMLParsedAsHTML + +class TestDetectsXMLParsedAsHTML(object): + + @pytest.mark.parametrize( + "markup,looks_like_xml", + [("No xml declaration", False), + ("<html>obviously HTML</html", False), + ("<?xml ><html>Actually XHTML</html>", False), + ("<?xml> < html>Tricky XHTML</html>", False), + ("<?xml ><no-html-tag>", True), + ] + ) + def test_warn_if_markup_looks_like_xml(self, markup, looks_like_xml): + # Test of our ability to guess at whether markup looks XML-ish + # _and_ not HTML-ish. + with patch('bs4.builder.DetectsXMLParsedAsHTML._warn') as mock: + for data in markup, markup.encode('utf8'): + result = DetectsXMLParsedAsHTML.warn_if_markup_looks_like_xml( + data + ) + assert result == looks_like_xml + if looks_like_xml: + assert mock.called + else: + assert not mock.called + mock.reset_mock() |