def test_set_attr_name_from_path_empty_value_should_be_ignored(shining): name = Path("./@bar") preprocessors.set_attr(path="//ul[@class='genres']/li", name=name, value="bar")(shining) data = xpather("//li[@Horror]/@Horror")(shining) assert data == []
def test_set_attr_value_from_str_should_set_attribute_for_selected_elements( shining): preprocessors.set_attr(path="//ul[@class='genres']/li", name="foo", value="bar")(shining) data = xpather("//li[@foo='bar']/text()")(shining) assert data == ["Horror", "Drama"]
def test_set_attr_name_from_path_should_set_attribute_for_selected_elements( shining): name = Path("./text()") preprocessors.set_attr(path="//ul[@class='genres']/li", name=name, value="bar")(shining) data = xpather("//li[@Horror]/@Horror")(shining) assert data == ["bar"]
def test_queries_starting_with_parent_should_be_ok(): element = xpather("//t2")(root)[0] selected = xpather("../@a")(element) assert selected == ["v"]
def test_absolute_queries_on_subelements_should_be_ok(): element = xpather("//t2")(root)[0] selected = xpather("//t1")(element) assert [s.tag for s in selected] == ["t1", "t1"]
def test_absolute_queries_should_be_ok(): selected = xpather("//t1")(root) assert [s.tag for s in selected] == ["t1", "t1"]
def test_attr_queries_should_return_strings(): selected = xpather(".//t1/@a")(root) assert selected == ["v"]
def test_descendant_text_queries_should_return_strings(): selected = xpather(".//t1//text()")(root) assert selected == ["foo", "bar"]
def test_child_text_queries_should_return_strings(): selected = xpather(".//t1/text()")(root) assert selected == ["foo"]
def test_remove_should_remove_selected_element(shining): preprocessors.remove(path="//tr[1]")(shining) data = xpather("//tr/td/a/text()")(shining) assert data == ["Shelley Duvall"]
def test_set_text_empty_value_should_be_ignored(shining): text = Path("./@foo") preprocessors.set_text(path="//ul[@class='genres']/li", text=text)(shining) data = xpather("//ul[@class='genres']/li/text()")(shining) assert data == []
def test_set_text_value_from_path_should_set_text_for_selected_elements( shining): text = Path("./text()", transform=transformers.lower) preprocessors.set_text(path="//ul[@class='genres']/li", text=text)(shining) data = xpather("//ul[@class='genres']/li/text()")(shining) assert data == ["horror", "drama"]
def test_set_text_value_from_str_should_set_text_for_selected_elements( shining): preprocessors.set_text(path="//ul[@class='genres']/li", text="Foo")(shining) data = xpather("//ul[@class='genres']/li/text()")(shining) assert data == ["Foo", "Foo"]
def test_set_attr_selected_none_should_not_cause_error(shining): preprocessors.set_attr(path="//foo", name="foo", value="bar")(shining) data = xpather("//li[@foo='bar']/@foo")(shining) assert data == []
def test_queries_starting_with_multiple_parents_should_be_ok(): element = xpather("//t2")(root)[0] selected = xpather("../../t1")(element) assert [s.tag for s in selected] == ["t1", "t1"]
def test_non_text_queries_should_return_elements(): selected = xpather(".//t1")(root) assert [s.tag for s in selected] == ["t1", "t1"]
def test_remove_selected_none_should_not_cause_error(shining): preprocessors.remove(path="//tr[50]")(shining) data = xpather("//tr/td/a/text()")(shining) assert data == ["Jack Nicholson", "Shelley Duvall"]