Esempio n. 1
0
def test_attribute_value_errors():
    with pytest.raises(DialectError, match="invalid character"):
        apply_dialects("""html(f"<div 'a'x")""", "html")
    with pytest.raises(DialectError, match="unexpected end of data"):
        apply_dialects('html(f"<div a{1}")', "html")
    with pytest.raises(DialectError, match="unexpected end of data"):
        apply_dialects('html(f"<div a")', "html")
    with pytest.raises(DialectError, match="unexpected end of data"):
        apply_dialects('html(f"<div a=")', "html")
Esempio n. 2
0
def test_tag_errors():
    with pytest.raises(DialectError, match="no token found"):
        apply_dialects('html(f"< >")', "html")
    with pytest.raises(DialectError, match="no token found"):
        apply_dialects('html(f"<>")', "html")
    with pytest.raises(DialectError, match="no token found"):
        apply_dialects("""html(f"<'")""", "html")
    with pytest.raises(DialectError, match="unexpected end of data"):
        apply_dialects('html(f"<")', "html")
Esempio n. 3
0
def test_attribute_name_errors():
    with pytest.raises(DialectError, match="expression not allowed"):
        apply_dialects('html(f"<div {1}>")', "html")
    with pytest.raises(DialectError, match="unexpected end of data"):
        apply_dialects('html(f"<div ")', "html")
    with pytest.raises(DialectError, match="no token found"):
        apply_dialects("""html(f"<div '")""", "html")
Esempio n. 4
0
def eval_html(src, variables=None):
    tree = apply_dialects(src, "html")
    if len(tree.body) > 1 or not isinstance(tree.body[0], ast.Expr):
        raise ValueError(f"Expected a single expression, not {src!r}")
    code = compile(ast.Expression(tree.body[0].value), "<string>", "eval")
    return eval(code, {"html": html}, variables)
Esempio n. 5
0
def test_structural_errors():
    with pytest.raises(DialectError, match="all opened tags not closed"):
        apply_dialects('html(f"<div>")', "html")