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")()))
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)
"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") aside = composite_tag("aside") audio = composite_tag("audio") b = composite_tag("b") base = leaf_tag("base") bdi = composite_tag("bdi") bdo = composite_tag("bdo")
def test_components_leaf_tag_with_multiple_tags(): my_tag = render(ly(YAML_COMPONENTS, "leaf_tag.with_multiple_tags")) your_tag = render(leaf_tag("sometag")(), "\n", leaf_tag("sometag")()) assert my_tag == your_tag
def test_components_leaf_tag_with_attrs(): my_tag = ly(YAML_COMPONENTS, "leaf_tag.with_attrs") your_tag = leaf_tag("sometag")(class_="row") assert my_tag == your_tag
def test_components_leaf_tag_empty(): my_tag = ly(YAML_COMPONENTS, "leaf_tag.empty") your_tag = leaf_tag("sometag")() assert my_tag == your_tag
def test_leaf_tag(): assert render(leaf_tag("input")()) == "<input />" assert render(input_()) == "<input />" assert render(input_("a")) == "<input a />" assert render(input_("a", b="c")) == '<input a b="c" />' assert render(input_(b="c")) == '<input b="c" />'