def attributes_are_generated_when_satisfying_elements(self): generator = HtmlGenerator() path = html_paths.path( [html_paths.element(["p"], class_names=["tip"])]) satisfy_html_path(generator, path) generator.text("Hello") assert_equal('<p class="tip">Hello', generator.html_string())
def elements_with_empty_string_text_are_not_generator(): generator = HtmlGenerator() generator.start("p") generator.start("span") generator.text("") generator.end_all() assert_equal("", generator.html_string())
def appending_another_html_generator_writes_out_elements_if_other_generator_is_not_empty(): generator = HtmlGenerator() generator.start("p") other = HtmlGenerator() other.text("Hello!") generator.append(other) assert_equal('<p>Hello!', generator.html_string())
def all_elements_are_closed_by_end_all(): generator = HtmlGenerator() generator.start("p") generator.start("span") generator.text("Hello!") generator.end_all() assert_equal("<p><span>Hello!</span></p>", generator.html_string())
def appending_another_html_generator_writes_out_elements_if_other_generator_is_not_empty( ): generator = HtmlGenerator() generator.start("p") other = HtmlGenerator() other.text("Hello!") generator.append(other) assert_equal('<p>Hello!', generator.html_string())
def only_missing_elements_are_generated_to_satisfy_plain_path_elements(self): generator = HtmlGenerator() generator.start("blockquote") generator.text("Hello") path = html_paths.path([html_paths.element(["blockquote"]), html_paths.element(["p"])]) satisfy_html_path(generator, path) generator.text("there") assert_equal('<blockquote>Hello<p>there', generator.html_string())
def elements_do_not_match_if_class_names_do_not_match(self): generator = HtmlGenerator() generator.start("p", {"class": "help"}) generator.text("Help") path = html_paths.path([html_paths.element(["p"], class_names=["tip"])]) satisfy_html_path(generator, path) generator.text("Tip") assert_equal('<p class="help">Help</p><p class="tip">Tip', generator.html_string())
def class_names_match_if_they_are_the_same(self): generator = HtmlGenerator() generator.start("p", {"class": "tip"}) generator.text("Help") path = html_paths.path([html_paths.element(["p"], class_names=["tip"])]) satisfy_html_path(generator, path) generator.text("Tip") assert_equal('<p class="tip">HelpTip', generator.html_string())
def fresh_element_matches_nothing(self): generator = HtmlGenerator() generator.start("blockquote") generator.start("p") generator.text("Hello") path = html_paths.path([html_paths.element(["blockquote"]), html_paths.element(["p"], fresh=True)]) satisfy_html_path(generator, path) generator.text("there") assert_equal('<blockquote><p>Hello</p><p>there', generator.html_string())
def mismatched_elements_are_closed_to_satisfy_plain_path_elements(self): generator = HtmlGenerator() generator.start("blockquote") generator.start("span") generator.text("Hello") path = html_paths.path([html_paths.element(["blockquote"]), html_paths.element(["p"])]) satisfy_html_path(generator, path) generator.text("there") assert_equal('<blockquote><span>Hello</span><p>there', generator.html_string())
def class_names_match_if_they_are_the_same(self): generator = HtmlGenerator() generator.start("p", {"class": "tip"}) generator.text("Help") path = html_paths.path( [html_paths.element(["p"], class_names=["tip"])]) satisfy_html_path(generator, path) generator.text("Tip") assert_equal('<p class="tip">HelpTip', generator.html_string())
def elements_do_not_match_if_class_names_do_not_match(self): generator = HtmlGenerator() generator.start("p", {"class": "help"}) generator.text("Help") path = html_paths.path( [html_paths.element(["p"], class_names=["tip"])]) satisfy_html_path(generator, path) generator.text("Tip") assert_equal('<p class="help">Help</p><p class="tip">Tip', generator.html_string())
def only_missing_elements_are_generated_to_satisfy_plain_path_elements( self): generator = HtmlGenerator() generator.start("blockquote") generator.text("Hello") path = html_paths.path( [html_paths.element(["blockquote"]), html_paths.element(["p"])]) satisfy_html_path(generator, path) generator.text("there") assert_equal('<blockquote>Hello<p>there', generator.html_string())
def mismatched_elements_are_closed_to_satisfy_plain_path_elements(self): generator = HtmlGenerator() generator.start("blockquote") generator.start("span") generator.text("Hello") path = html_paths.path( [html_paths.element(["blockquote"]), html_paths.element(["p"])]) satisfy_html_path(generator, path) generator.text("there") assert_equal('<blockquote><span>Hello</span><p>there', generator.html_string())
def fresh_element_matches_nothing(self): generator = HtmlGenerator() generator.start("blockquote") generator.start("p") generator.text("Hello") path = html_paths.path([ html_paths.element(["blockquote"]), html_paths.element(["p"], fresh=True) ]) satisfy_html_path(generator, path) generator.text("there") assert_equal('<blockquote><p>Hello</p><p>there', generator.html_string())
def opening_tag_can_have_attributes(): generator = HtmlGenerator() generator.start("p", {"data-blah": "42"}) generator.text("Hello!") generator.end() assert_equal('<p data-blah="42">Hello!</p>', generator.html_string())
def html_escapes_text(): generator = HtmlGenerator() generator.text("<") assert_equal("<", generator.html_string())
def attributes_are_generated_when_satisfying_elements(self): generator = HtmlGenerator() path = html_paths.path([html_paths.element(["p"], class_names=["tip"])]) satisfy_html_path(generator, path) generator.text("Hello") assert_equal('<p class="tip">Hello', generator.html_string())
def plain_elements_are_generated_to_satisfy_plain_path_elements(self): generator = HtmlGenerator() path = html_paths.path([html_paths.element(["p"])]) satisfy_html_path(generator, path) generator.text("Hello!") assert_equal('<p>Hello!', generator.html_string())