def collapsible_element_can_collapse_into_previous_fresh_element(): assert_equal( [html.element("p", {}, [html.text("One"), html.text("Two")])], html.collapse([ html.element("p", {}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def collapsible_element_can_collapse_into_previous_fresh_element(): assert_equal([html.element( "p", {}, [html.text("One"), html.text("Two")])], html.collapse([ html.element("p", {}, [html.text("One")]), html.collapsible_element("p", {}, [html.text("Two")]) ]))
def empty_children_are_removed(): assert_equal( html.strip_empty([ html.element("ul", {}, [ html.element("li", {}, [html.text("")]), html.element("li", {}, [html.text("H")]), ]) ]), [html.element("ul", {}, [html.element("li", {}, [html.text("H")])])])
def table_nodes_are_reserved(): elements = [ html.element('table', {}, [ html.element('tr', {'rowspan': 2}, [ html.element('td', {}, [html.text('H')]), ]), html.element('tr', []), ]) ] assert_equal(elements, html.strip_empty(elements))
def empty_children_are_removed(): assert_equal( html.strip_empty([html.element("ul", {}, [ html.element("li", {}, [html.text("")]), html.element("li", {}, [html.text("H")]), ])]), [html.element("ul", {}, [ html.element("li", {}, [html.text("H")]) ])])
def when_separator_is_present_then_separator_is_prepended_to_collapsed_element(): assert_equal( [ html.element("pre", collapsible=False, children=[ html.text("Hello"), html.text("\n"), html.text(" the"), html.text("re") ]) ], html.collapse([ html.element("pre", collapsible=False, children=[html.text("Hello")]), html.element("pre", collapsible=True, separator="\n", children=[html.text(" the"), html.text("re")]), ]), )
def when_separator_is_present_then_separator_is_prepended_to_collapsed_element( ): assert_equal( [ html.element("pre", collapsible=False, children=[ html.text("Hello"), html.text("\n"), html.text(" the"), html.text("re") ]) ], html.collapse([ html.element("pre", collapsible=False, children=[html.text("Hello")]), html.element("pre", collapsible=True, separator="\n", children=[html.text(" the"), html.text("re")]), ]), )
def consecutive_fresh_elements_are_not_collapsed(): assert_equal( html.collapse([html.element("p"), html.element("p")]), [html.element("p"), html.element("p")])
def convert_image(image): with image.open() as image_file: return [ html.element("img", {"alt": image_file.read().decode("ascii")}) ]
def self_closing_elements_are_never_empty(): assert_equal([html.element("br")], html.strip_empty([html.element("br")]))
def elements_with_non_empty_children_are_not_stripped(): assert_equal([html.element("p", {}, [html.text("H")])], html.strip_empty([html.element("p", {}, [html.text("H")])]))
def self_closing_elements_are_never_empty(): assert_equal( [html.element("br")], html.strip_empty([html.element("br")]))
def elements_with_only_empty_children_are_stripped(): assert_equal( [], html.strip_empty([html.element("p", {}, [html.text("")])]))
def elements_with_no_children_are_stripped(): assert_equal( [], html.strip_empty([html.element("p")]))
def elements_with_non_empty_children_are_not_stripped(): assert_equal( [html.element("p", {}, [html.text("H")])], html.strip_empty([html.element("p", {}, [html.text("H")])]))
def consecutive_fresh_elements_are_not_collapsed(): assert_equal(html.collapse([html.element("p"), html.element("p")]), [html.element("p"), html.element("p")])
def elements_with_no_children_are_stripped(): assert_equal([], html.strip_empty([html.element("p")]))
def convert_image(image): with image.open() as image_file: return [html.element("img", {"alt": image_file.read().decode("ascii")})]
def elements_with_only_empty_children_are_stripped(): assert_equal([], html.strip_empty([html.element("p", {}, [html.text("")])]))