示例#1
0
def test_invalid_xpath_expr(element, expr):
    extractor = XPathExtractor(expr)
    with pytest.raises(ExprError) as catch:
        extractor.extract(element)

    exc = catch.value
    assert exc.extractor is extractor
    assert isinstance(exc.exc, XPathEvalError)
示例#2
0
def test_invalid_xpath_expr_by_extract(element, expr):
    extractor = XPathExtractor(expr)
    assert not extractor.built
    with pytest.raises(ExprError) as catch:
        extractor.extract(element)

    assert not extractor.built
    exc = catch.value
    assert exc.extractor is extractor
    assert isinstance(exc.exc, XPathError)
    assert re.match(r"ExprError with .+? raised by .+? extracting", str(exc))
示例#3
0
def test_invalid_xpath_expr_by_XPathEvalError_from_extract(element, expr):
    extractor = XPathExtractor(expr)
    with pytest.raises(ExprError) as catch:
        extractor.extract(element)

    exc = catch.value
    assert exc.extractor is extractor
    # Third Party Library
    from lxml.etree import XPathEvalError

    assert isinstance(exc.exc, XPathEvalError)
    assert re.match(r"ExprError with .+? raised by .+? extracting", str(exc))
示例#4
0
def test_xpath_result_not_list(element):
    extractor = XPathExtractor("normalize-space(//span)")

    assert extractor.extract(element) == "a"

    with pytest.warns(UserWarning):
        extractor.extract_first(element) == "a"
示例#5
0
def test_xpath_result_not_list(element):
    extractor = XPathExtractor("normalize-space(//span)")
    assert extractor.extract(element) == ["a"]
    assert extractor.extract_first(element) == "a"