Exemple #1
0
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 == []
Exemple #2
0
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"]
Exemple #3
0
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"]
Exemple #4
0
def test_queries_starting_with_parent_should_be_ok():
    element = xpather("//t2")(root)[0]
    selected = xpather("../@a")(element)
    assert selected == ["v"]
Exemple #5
0
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"]
Exemple #6
0
def test_absolute_queries_should_be_ok():
    selected = xpather("//t1")(root)
    assert [s.tag for s in selected] == ["t1", "t1"]
Exemple #7
0
def test_attr_queries_should_return_strings():
    selected = xpather(".//t1/@a")(root)
    assert selected == ["v"]
Exemple #8
0
def test_descendant_text_queries_should_return_strings():
    selected = xpather(".//t1//text()")(root)
    assert selected == ["foo", "bar"]
Exemple #9
0
def test_child_text_queries_should_return_strings():
    selected = xpather(".//t1/text()")(root)
    assert selected == ["foo"]
Exemple #10
0
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"]
Exemple #11
0
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 == []
Exemple #12
0
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"]
Exemple #13
0
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"]
Exemple #14
0
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 == []
Exemple #15
0
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"]
Exemple #16
0
def test_non_text_queries_should_return_elements():
    selected = xpather(".//t1")(root)
    assert [s.tag for s in selected] == ["t1", "t1"]
Exemple #17
0
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"]