Esempio n. 1
0
def test_xpath_keep_pick_mode():
    mock = Mock()
    value = ["a", "b", "c"]
    mock.tree.xpath.return_value = value

    text = XPathTextProperty(xpath="//foo-path", etree_attr="tree", pick_mode="keep")
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//foo-path")
    assert rv == value
Esempio n. 2
0
def test_xpath_default_attr_name():
    with raises(TypeError):
        XPathTextProperty()

    text = XPathTextProperty(xpath="//path")
    assert text.xpath == "//path"
    assert text.attr_names["etree_attr"] == "etree"
    assert text.options["strip_spaces"] is False
    assert text.options["pick_mode"] == "join"
    assert text.options["joiner"] == " "
Esempio n. 3
0
def test_xpath_keep_pick_mode():
    mock = Mock()
    value = ['a', 'b', 'c']
    mock.tree.xpath.return_value = value

    text = XPathTextProperty(xpath="//foo-path",
                             etree_attr="tree",
                             pick_mode="keep")
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//foo-path")
    assert rv == value
Esempio n. 4
0
def test_xpath_with_striping_spaces():
    mock = Mock()
    mock.tree.xpath.return_value = [" a ", "\n b \n", "\n\n c  \t"]

    # strip_spaces and join
    text = XPathTextProperty(xpath="//foo-path", etree_attr="tree", pick_mode="join", strip_spaces=True)
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//foo-path")
    assert rv == "a b c"

    # strip_spaces and first
    text = XPathTextProperty(xpath="//bar-path", etree_attr="tree", pick_mode="first", strip_spaces=True)
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//bar-path")
    assert rv == "a"
Esempio n. 5
0
def test_xpath_without_spaces():
    mock = Mock()
    mock.tree.xpath.return_value = ["a", "b", "c"]

    # pick_mode: join
    text = XPathTextProperty(xpath="//path", etree_attr="tree", pick_mode="join", joiner="|")
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//path")
    assert rv == "a|b|c"

    # pick_mode: first
    text = XPathTextProperty(xpath="//another-path", etree_attr="tree", pick_mode="first")
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//another-path")
    assert rv == "a"
Esempio n. 6
0
def test_xpath_without_spaces():
    mock = Mock()
    mock.tree.xpath.return_value = ["a", "b", "c"]

    # pick_mode: join
    text = XPathTextProperty(xpath="//path",
                             etree_attr="tree",
                             pick_mode="join",
                             joiner="|")
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//path")
    assert rv == "a|b|c"

    # pick_mode: first
    text = XPathTextProperty(xpath="//another-path",
                             etree_attr="tree",
                             pick_mode="first")
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//another-path")
    assert rv == "a"
Esempio n. 7
0
def test_xpath_with_striping_spaces():
    mock = Mock()
    mock.tree.xpath.return_value = [" a ", "\n b \n", "\n\n c  \t"]

    # strip_spaces and join
    text = XPathTextProperty(xpath="//foo-path",
                             etree_attr="tree",
                             pick_mode="join",
                             strip_spaces=True)
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//foo-path")
    assert rv == "a b c"

    # strip_spaces and first
    text = XPathTextProperty(xpath="//bar-path",
                             etree_attr="tree",
                             pick_mode="first",
                             strip_spaces=True)
    rv = text.provide_value(mock)
    mock.tree.xpath.assert_called_with("//bar-path")
    assert rv == "a"
Esempio n. 8
0
def test_xpath_invalid_pick_mode():
    with raises(ValueError) as excinfo:
        text = XPathTextProperty(xpath="//foo-path", pick_mode="unknown")
        text.provide_value(Mock())
    assert "unknown" in repr(excinfo.value)
Esempio n. 9
0
def test_xpath_invalid_pick_mode():
    with raises(ValueError) as excinfo:
        text = XPathTextProperty(xpath="//foo-path", pick_mode="unknown")
        text.provide_value(Mock())
    assert "unknown" in repr(excinfo.value)