Beispiel #1
0
def test_leaf_tag():
    with pytest.raises(ValueError):
        render(leaf_tag("a")(leaf_tag("b")))
    with pytest.raises(ValueError):
        render(composite_tag("a")(composite_tag("b")))

    with pytest.raises(ValueError):
        render(leaf_tag("a")(leaf_tag("b")()))
    with pytest.raises(ValueError):
        render(composite_tag("a")(composite_tag("b")()))
Beispiel #2
0
def test_composite_tag():
    assert render(composite_tag("p")()()) == "<p></p>"
    assert render(p()(txt("x"))) == "<p>x</p>"
    assert render(p(class_="y")(txt("x"))) == '<p class="y">x</p>'
    assert render(p("a")(txt("x"))) == "<p a>x</p>"
    assert render(p("a", b="c")(txt("x"))) == '<p a b="c">x</p>'
    assert render(p(b="c")(txt("x"))) == '<p b="c">x</p>'
    assert render(p(b="c")(p()(txt("x")))) == '<p b="c"><p>x</p></p>'
Beispiel #3
0
def _to_element(tagname, attributes=None, inner=None):
    """Format given values into an HTML elements."""

    if not attributes:
        if inner is None:
            return leaf_tag(tagname)()
        return composite_tag(tagname)()(inner)

    bool_props, kv_props = [], {}
    for k, v in attributes.items():
        if v is True:
            bool_props.append(k)
        elif isinstance(v, str):
            kv_props[k] = v
        else:
            raise ValueError(
                f"{kv_props}\n^^^ `{v}`: Expected `str` but got `{type(v)}`. "
                f"Some examples for you:\n{VALID_FORMAT}")

    if inner is None:
        return leaf_tag(tagname)(*bool_props, **kv_props)
    return composite_tag(tagname)(*bool_props, **kv_props)(inner)
Beispiel #4
0
    "thead",
    "time",
    "title",
    "tr",
    "track",
    "tspan",
    "u",
    "ul",
    "use",
    "var",
    "view",
    "video",
    "wbr",
]

a = composite_tag("a")

abbr = composite_tag("abbr")

address = composite_tag("address")

animate = composite_tag("animate")

animateMotion = composite_tag("animateMotion")

animateTransform = composite_tag("animateTransform")

area = leaf_tag("area")

article = composite_tag("article")
def test_components_leaf_tag_with_multiple_tags():
    my_tag = render(ly(YAML_COMPONENTS, "composite_tag.with_multiple_tags"))
    your_tag = render(
        composite_tag("sometag")()("1"), "\n",
        composite_tag("sometag")()("2"))
    assert my_tag == your_tag
def test_components_composite_tag_vals():
    my_tag = ly(YAML_COMPONENTS, "composite_tag.with_nested_tag")
    your_tag = composite_tag("sometag")(class_="row")(e.i()("val"))
    assert my_tag == your_tag
def test_components_composite_tag_vals():
    my_tag = ly(YAML_COMPONENTS, "composite_tag.with_attrs_and_vals")
    your_tag = composite_tag("sometag")(class_="row")("val1", "val2")
    assert my_tag == your_tag
def test_components_composite_tag_with_attrs():
    my_tag = ly(YAML_COMPONENTS, "composite_tag.with_attrs")
    your_tag = composite_tag("sometag")(class_="row")()
    assert my_tag == your_tag
def test_components_composite_tag_empty():
    my_tag = ly(YAML_COMPONENTS, "composite_tag.empty")
    your_tag = composite_tag("sometag")()()
    assert my_tag == your_tag