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)
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))
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))
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"
def test_xpath_result_not_list(element): extractor = XPathExtractor("normalize-space(//span)") assert extractor.extract(element) == ["a"] assert extractor.extract_first(element) == "a"