示例#1
0
 def test_elements_will_end_in_sequence(self):
     out = HTML()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.end_tag("foo")
     assert str(out) == "<foo><bar>baz</bar></foo>"
示例#2
0
 def test_can_write_raw_html(self):
     out = HTML()
     out.start_tag("foo")
     out.write_text("bar")
     out.end_tag("foo")
     out.write_html("<baz>qux</baz>")
     assert str(out) == "<foo>bar</foo><baz>qux</baz>"
示例#3
0
 def test_elements_will_all_end_on_close(self):
     out = HTML()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.close()
     assert str(out) == "<foo><bar>baz</bar></foo>"
示例#4
0
 def test_can_write_nested_elements(self):
     out = HTML()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.end_tag("bar")
     out.end_tag("foo")
     assert str(out) == "<foo><bar>baz</bar></foo>"
示例#5
0
 def test_void_elements_do_not_need_to_end(self):
     out = HTML()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.start_tag("qux", void=True)
     out.close()
     assert str(out) == "<foo><bar>baz<qux></bar></foo>"
示例#6
0
 def test_cannot_write_badly_nested_elements(self):
     out = HTML()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.end_tag("foo")
     try:
         out.end_tag("bar")
         assert False
     except ValueError:
         assert True
示例#7
0
 def test_can_write_tag_with_attributes_containing_entities(self):
     out = HTML()
     out.start_tag("foo", {"bar": "baz", "spam": "bacon & eggs"})
     out.write_text("qux")
     out.end_tag("foo")
     assert str(out) == '<foo bar="baz" spam="bacon &amp; eggs">qux</foo>'
示例#8
0
 def test_can_use_default_end_tag(self):
     out = HTML()
     out.start_tag("foo")
     out.write_text("bar")
     out.end_tag()
     assert str(out) == "<foo>bar</foo>"
示例#9
0
 def test_can_write_start_and_end_tags(self):
     out = HTML()
     out.start_tag("foo")
     out.write_text("bar")
     out.end_tag("foo")
     assert str(out) == "<foo>bar</foo>"
示例#10
0
 def test_can_write_void_tag(self):
     out = HTML()
     out.write_text("foo")
     out.start_tag("br")
     out.write_text("bar")
     assert str(out) == "foo<br>bar"