From 20195e7a79b279b3f92ca1b135534066cf5d8d98 Mon Sep 17 00:00:00 2001 From: Constantin Hong Date: Tue, 7 May 2024 23:25:45 +0900 Subject: [PATCH] tests/test_xpath_selector_unit/test: Fix test and add more small tests for fragment --- changedetectionio/tests/test_xpath_selector_unit.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/changedetectionio/tests/test_xpath_selector_unit.py b/changedetectionio/tests/test_xpath_selector_unit.py index 131054c5..7b9c57d1 100644 --- a/changedetectionio/tests/test_xpath_selector_unit.py +++ b/changedetectionio/tests/test_xpath_selector_unit.py @@ -205,22 +205,27 @@ def test_trips(html_content, xpath, answer): DOM_violation_two_html_root_element = """ -

Hello absurd world

+

Hello world

First paragraph.

-

Hello absurd world

+

Hello world

Browsers parse this part by fixing it but lxml doesn't and returns two root element node

Therefore, if the path is /html/body/p[1], lxml(libxml2) returns two element nodes not one.

""" @pytest.mark.parametrize("html_content", [DOM_violation_two_html_root_element]) @pytest.mark.parametrize("xpath, answer", [ + ("/html/body/p[1]", "First paragraph."), ("/html/body/p[1]", "Browsers parse this part by fixing it but lxml doesn't and returns two root element node"), + ("//html/body/p[1]", "First paragraph."), + ("//html/body/p[1]", "Browsers parse this part by fixing it but lxml doesn't and returns two root element node"), + ("//body/p[1]", "First paragraph."), + ("//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): html_content = html_tools.xpath_filter(xpath, html_content, append_pretty_line_formatting=True) assert type(html_content) == str - assert answer not in html_content + assert answer in html_content