# Path: htmlgen/element.py
# class Element(NonVoidElement):
# 
#     """Base generator for HTML elements with children.
# 
#     This includes most elements, like <body>, <div>, <span>, <strong>, etc.
# 
#         >>> link = Element("a")
#         >>> link.set_attribute("href", "http://www.example.com/")
#         >>> link.append("Test Link")
#         >>> str(link)
#         '<a href="http://www.example.com/">Test Link</a>'
# 
#     append() and extend() escape reserved HTML characters in string, but
#     not in sub-generators:
# 
#         >>> span = Element("span")
#         >>> span.add_css_classes("my-css")
#         >>> span.set_style("color", "red")
#         >>> span.append("Test & Test")
#         >>> str(span)
#         '<span class="my-css" style="color: red">Test &amp; Test</span>'
# 
#     append_raw() and extend_raw() do not do any escaping. Do not use these
#     methods with strings from untrusted sources!
# 
#         >>> span = Element("span")
#         >>> span.append_raw("Test<br/>Test")
#         >>> str(span)
#         '<span>Test<br/>Test</span>'
# 
#     Instead of appending children to elements, the generate_children()
#     method can be overwritten. This is generally preferred for element
#     sub-classes that are not meant to be extended by users, since it avoids
#     constructing the HTML tree in memory.
# 
#         >>> class MyElement(Element):
#         ...     def generate_children(self):
#         ...         yield "Hello, "
#         ...         child = Element("strong")
#         ...         child.append("World!")
#         ...         yield child
#         >>> str(MyElement("div"))
#         '<div>Hello, <strong>World!</strong></div>'
# 
#     """
# 
#     def __init__(self, element_name):
#         super().__init__(element_name)
#         self.children = HTMLChildGenerator()
# 
#     def __bool__(self):
#         return True
# 
#     def __getattr__(self, item):
#         return getattr(self.children, item)
# 
#     def __len__(self):
#         """Return the number of children.
# 
#         A sub-generator is counted as one child.
# 
#         """
#         return len(self.children)
# 
#     def __nonzero__(self):
#         return True
# 
#     def generate_children(self):
#         """Return an iterator over the children of this element.
# 
#         This method can be overridden by sub-classes.
# 
#         """
#         return self.children
# 
# class VoidElement(ElementBase):
# 
#     """Base generator for content-less HTML elements.
# 
#     These are elements like <br> or <link>.
# 
#         >>> link = VoidElement("link")
#         >>> link.set_attribute("rel", "stylesheet")
#         >>> str(link)
#         '<link rel="stylesheet"/>'
# 
#     """
# 
#     def generate(self):
#         yield self.render_start_tag() + "/>"
# 
# class NonVoidElement(ElementBase):
# 
#     """Base generator for non-void HTML elements.
# 
#     Sub-classes must override the generate_children method:
# 
#         >>> class MyElement(NonVoidElement):
#         ...     def generate_children(self):
#         ...         yield "Hello World!"
#         >>> element = MyElement("div")
#         >>> str(element)
#         '<div>Hello World!</div>'
# 
#     """
# 
#     def generate(self):
#         yield self.render_start_tag() + ">"
#         for element in self.generate_children():
#             yield element
#         yield "</" + self.element_name + ">"
# 
#     def generate_children(self):
#         """Return an iterator over the children of this element.
# 
#         This method must be overridden by sub-classes.
# 
#         """
#         raise NotImplementedError()


import re
from unittest import TestCase
from asserts import (
    assert_false,
    assert_true,
    assert_equal,
    assert_is_none,
    assert_raises,
)
from htmlgen.element import Element, VoidElement, NonVoidElement
        element.data["foo"] = "bar"
        element.data["abc-def"] = "Another Value"
        assert_equal(
            [b'<div data-abc-def="Another Value" data-foo="bar">', b"</div>"],
            list(iter(element)),
        )

    def test_data_get(self):
        element = Element("div")
        element.data["foo"] = "bar"
        assert_equal("bar", element.data["foo"])

    def test_data_get_not_set(self):
        element = Element("div")
        with assert_raises(KeyError):
            element.data["foo"]

    def test_data_overwrite(self):
        element = Element("div")
        element.data["foo"] = "bar"
        element.data["foo"] = "new"
        assert_equal([b'<div data-foo="new">', b"</div>"], list(iter(element)))

    def test_data_delete(self):
        element = Element("div")
        element.data["foo"] = "bar"
        del element.data["foo"]
        assert_equal([b"<div>", b"</div>"], list(iter(element)))

    def test_data_delete_unknown(self):

# Path: htmlgen/element.py
# class Element(NonVoidElement):
# 
#     """Base generator for HTML elements with children.
# 
#     This includes most elements, like <body>, <div>, <span>, <strong>, etc.
# 
#         >>> link = Element("a")
#         >>> link.set_attribute("href", "http://www.example.com/")
#         >>> link.append("Test Link")
#         >>> str(link)
#         '<a href="http://www.example.com/">Test Link</a>'
# 
#     append() and extend() escape reserved HTML characters in string, but
#     not in sub-generators:
# 
#         >>> span = Element("span")
#         >>> span.add_css_classes("my-css")
#         >>> span.set_style("color", "red")
#         >>> span.append("Test & Test")
#         >>> str(span)
#         '<span class="my-css" style="color: red">Test &amp; Test</span>'
# 
#     append_raw() and extend_raw() do not do any escaping. Do not use these
#     methods with strings from untrusted sources!
# 
#         >>> span = Element("span")
#         >>> span.append_raw("Test<br/>Test")
#         >>> str(span)
#         '<span>Test<br/>Test</span>'
# 
#     Instead of appending children to elements, the generate_children()
#     method can be overwritten. This is generally preferred for element
#     sub-classes that are not meant to be extended by users, since it avoids
#     constructing the HTML tree in memory.
# 
#         >>> class MyElement(Element):
#         ...     def generate_children(self):
#         ...         yield "Hello, "
#         ...         child = Element("strong")
#         ...         child.append("World!")
#         ...         yield child
#         >>> str(MyElement("div"))
#         '<div>Hello, <strong>World!</strong></div>'
# 
#     """
# 
#     def __init__(self, element_name):
#         super().__init__(element_name)
#         self.children = HTMLChildGenerator()
# 
#     def __bool__(self):
#         return True
# 
#     def __getattr__(self, item):
#         return getattr(self.children, item)
# 
#     def __len__(self):
#         """Return the number of children.
# 
#         A sub-generator is counted as one child.
# 
#         """
#         return len(self.children)
# 
#     def __nonzero__(self):
#         return True
# 
#     def generate_children(self):
#         """Return an iterator over the children of this element.
# 
#         This method can be overridden by sub-classes.
# 
#         """
#         return self.children
# 
# class VoidElement(ElementBase):
# 
#     """Base generator for content-less HTML elements.
# 
#     These are elements like <br> or <link>.
# 
#         >>> link = VoidElement("link")
#         >>> link.set_attribute("rel", "stylesheet")
#         >>> str(link)
#         '<link rel="stylesheet"/>'
# 
#     """
# 
#     def generate(self):
#         yield self.render_start_tag() + "/>"
# 
# class NonVoidElement(ElementBase):
# 
#     """Base generator for non-void HTML elements.
# 
#     Sub-classes must override the generate_children method:
# 
#         >>> class MyElement(NonVoidElement):
#         ...     def generate_children(self):
#         ...         yield "Hello World!"
#         >>> element = MyElement("div")
#         >>> str(element)
#         '<div>Hello World!</div>'
# 
#     """
# 
#     def generate(self):
#         yield self.render_start_tag() + ">"
#         for element in self.generate_children():
#             yield element
#         yield "</" + self.element_name + ">"
# 
#     def generate_children(self):
#         """Return an iterator over the children of this element.
# 
#         This method must be overridden by sub-classes.
# 
#         """
#         raise NotImplementedError()


# Path: test_htmlgen/element.py
import re
from unittest import TestCase
from asserts import (
    assert_false,
    assert_true,
    assert_equal,
    assert_is_none,
    assert_raises,
)
from htmlgen.element import Element, VoidElement, NonVoidElement

        element.data["foo"] = "bar"
        element.data["abc-def"] = "Another Value"
        assert_equal(
            [b'<div data-abc-def="Another Value" data-foo="bar">', b"</div>"],
            list(iter(element)),
        )

    def test_data_get(self):
        element = Element("div")
        element.data["foo"] = "bar"
        assert_equal("bar", element.data["foo"])

    def test_data_get_not_set(self):
        element = Element("div")
        with assert_raises(KeyError):
            element.data["foo"]

    def test_data_overwrite(self):
        element = Element("div")
        element.data["foo"] = "bar"
        element.data["foo"] = "new"
        assert_equal([b'<div data-foo="new">', b"</div>"], list(iter(element)))

    def test_data_delete(self):
        element = Element("div")
        element.data["foo"] = "bar"
        del element.data["foo"]
        assert_equal([b"<div>", b"</div>"], list(iter(element)))

    def test_data_delete_unknown(self):

        element = Element("div")