예제 #1
0
def test_xpath():
    document = etree.fromstring('<root><a/><b/></root>')
    transformation = Transformation(Rule('//a', lib.set_text('x')))
    result = transformation(document)
    assert result.text is None
    assert result.find('a').text == 'x'
    assert result.find('b').text is None
예제 #2
0
def test_attributes():
    document = etree.fromstring('<root><a b="x"/><a b="y"/></root>')
    transformation = Transformation(Rule({'b': 'x'}, lib.set_text('x')))
    result = transformation(document)
    assert result.text is None
    assert result[0].text == 'x'
    assert result[1].text is None
예제 #3
0
def test_attributes(constraint):
    document = Document('<root><a b="x"/><a b="y"/></root>')
    transformation = Transformation(Rule(constraint, lib.set_text("x")))
    result = transformation(document).root
    assert not result._data_node._exists
    assert result[0].full_text == "x", str(result)
    assert not len(result[1])
예제 #4
0
def test_OneOf():
    document = etree.fromstring('<root x="x"><a x="x"/><b x="x"/></root>')
    transformation = Transformation(
        Rule(OneOf('a', 'b', {'x': 'x'}), lib.set_text('x')))
    result = transformation(document)
    assert result.text == 'x'
    assert all(x.text is None for x in result)
예제 #5
0
def test_xpath(xpath):
    document = Document("<root><a/><b/></root>")
    transformation = Transformation(Rule(xpath, lib.set_text("x")))
    result = transformation(document).root
    assert not result._data_node._exists
    assert first(result.css_select("a")).full_text == "x"
    assert first(result.css_select("b")).full_text == ""
예제 #6
0
def test_OneOf():
    document = Document('<root x="x"><a x="x"/><b x="x"/></root>')
    transformation = Transformation(
        Rule(OneOf("a", "b", {"x": "x"}), lib.set_text("x")))
    result = transformation(document).root
    assert result[0] == "x"

    assert all(x.full_text == "" for x in result.child_nodes(is_tag_node))
예제 #7
0
def test_any_element():
    document = etree.fromstring('<root><a/><b/></root>')
    transformation = Transformation(Rule('*', lib.set_text('x')))
    for element in transformation(document):
        assert element.text == 'x'
예제 #8
0
def test_Any():
    document = etree.fromstring('<root><a/><b/></root>')
    transformation = Transformation(Rule(Any('a', 'b'), lib.set_text('x')))
    result = transformation(document)
    assert result.text is None
    assert all(x.text == 'x' for x in result)
예제 #9
0
파일: test_lib.py 프로젝트: ra2003/inxs
def test_set_text():
    node = new_tag_node("pre")
    transformation = Transformation(lib.put_variable("x", "Hello world."),
                                    Rule("/", lib.set_text(Ref("x"))))
    assert str(transformation(node)) == "<pre>Hello world.</pre>"
예제 #10
0
def test_any_element():
    document = Document("<root><a/><b/></root>")
    transformation = Transformation(Rule("*", lib.set_text("x")))
    for node in transformation(document).root.child_nodes():
        assert node[0] == "x"
예제 #11
0
def test_Any():
    document = Document("<root><a/><b/></root>")
    transformation = Transformation(Rule(Any("a", "b"), lib.set_text("x")))
    result = transformation(document).root
    assert not result._data_node._exists
    assert all(x.content == "x" for x in result.child_nodes(is_text_node))