From 220f484ee97e049b11a8901c298c2ad8cb9fec4c Mon Sep 17 00:00:00 2001 From: Constantin Hong Date: Wed, 8 May 2024 00:00:08 +0900 Subject: [PATCH] tests/test_xpath_selector_unit/test: Check error occurs. --- changedetectionio/tests/test_xpath_selector_unit.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/changedetectionio/tests/test_xpath_selector_unit.py b/changedetectionio/tests/test_xpath_selector_unit.py index 7b9c57d1..315a50fb 100644 --- a/changedetectionio/tests/test_xpath_selector_unit.py +++ b/changedetectionio/tests/test_xpath_selector_unit.py @@ -226,6 +226,18 @@ DOM_violation_two_html_root_element = """ ("//body/p[1]", "Browsers parse this part by fixing it but lxml doesn't and returns two root element node"), ]) def test_trips(html_content, xpath, answer): + + + # In normal situation, DOM's root element node is only one. So Exception occurs. + with pytest.raises(Exception): + from lxml import etree, html + import elementpath + from elementpath.xpath3 import XPath3Parser + parser = etree.HTMLParser() + tree = html.fromstring(bytes(doc, encoding='utf-8'), parser=parser) + # Error will occur. + r = elementpath.select(tree, path.strip(), namespaces={'re': 'http://exslt.org/regular-expressions'}, parser=XPath3Parser) + html_content = html_tools.xpath_filter(xpath, html_content, append_pretty_line_formatting=True) assert type(html_content) == str assert answer in html_content