Ejemplo n.º 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 == []
Ejemplo n.º 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"]
Ejemplo n.º 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"]
Ejemplo n.º 4
0
def test_queries_starting_with_parent_should_be_ok():
    element = xpather("//t2")(root)[0]
    selected = xpather("../@a")(element)
    assert selected == ["v"]
Ejemplo n.º 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"]
Ejemplo n.º 6
0
def test_absolute_queries_should_be_ok():
    selected = xpather("//t1")(root)
    assert [s.tag for s in selected] == ["t1", "t1"]
Ejemplo n.º 7
0
def test_attr_queries_should_return_strings():
    selected = xpather(".//t1/@a")(root)
    assert selected == ["v"]
Ejemplo n.º 8
0
def test_descendant_text_queries_should_return_strings():
    selected = xpather(".//t1//text()")(root)
    assert selected == ["foo", "bar"]
Ejemplo n.º 9
0
def test_child_text_queries_should_return_strings():
    selected = xpather(".//t1/text()")(root)
    assert selected == ["foo"]
Ejemplo n.º 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"]
Ejemplo n.º 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 == []
Ejemplo n.º 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"]
Ejemplo n.º 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"]
Ejemplo n.º 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 == []
Ejemplo n.º 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"]
Ejemplo n.º 16
0
def test_non_text_queries_should_return_elements():
    selected = xpather(".//t1")(root)
    assert [s.tag for s in selected] == ["t1", "t1"]
Ejemplo n.º 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"]