Ejemplo n.º 1
0
 def test_can_write_raw_html(self):
     out = HTMLOutputStream()
     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>"
Ejemplo n.º 2
0
 def test_void_elements_do_not_need_to_end(self):
     out = HTMLOutputStream()
     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>"
Ejemplo n.º 3
0
 def test_cannot_write_badly_nested_elements(self):
     out = HTMLOutputStream()
     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
Ejemplo n.º 4
0
 def test_elements_will_all_end_on_close(self):
     out = HTMLOutputStream()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.close()
     assert str(out) == "<foo><bar>baz</bar></foo>"
Ejemplo n.º 5
0
 def test_elements_will_end_in_sequence(self):
     out = HTMLOutputStream()
     out.start_tag("foo")
     out.start_tag("bar")
     out.write_text("baz")
     out.end_tag("foo")
     assert str(out) == "<foo><bar>baz</bar></foo>"
Ejemplo n.º 6
0
 def test_can_write_nested_elements(self):
     out = HTMLOutputStream()
     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>"
Ejemplo n.º 7
0
 def test_can_write_tag_with_attributes_containing_entities(self):
     out = HTMLOutputStream()
     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>'
Ejemplo n.º 8
0
 def test_can_use_default_end_tag(self):
     out = HTMLOutputStream()
     out.start_tag("foo")
     out.write_text("bar")
     out.end_tag()
     assert str(out) == "<foo>bar</foo>"
Ejemplo n.º 9
0
 def test_can_write_start_and_end_tags(self):
     out = HTMLOutputStream()
     out.start_tag("foo")
     out.write_text("bar")
     out.end_tag("foo")
     assert str(out) == "<foo>bar</foo>"
Ejemplo n.º 10
0
 def test_can_write_void_tag(self):
     out = HTMLOutputStream()
     out.write_text("foo")
     out.start_tag("br")
     out.write_text("bar")
     assert str(out) == "foo<br>bar"
Ejemplo n.º 11
0
 def test_can_write_text_with_greater_than_symbol(self):
     out = HTMLOutputStream()
     out.write_text("foo > bar")
     assert str(out) == "foo &gt; bar"
Ejemplo n.º 12
0
 def test_can_write_text_with_less_than_symbol(self):
     out = HTMLOutputStream()
     out.write_text("foo < bar")
     assert str(out) == "foo &lt; bar"
Ejemplo n.º 13
0
 def test_can_write_text_with_apostrophes(self):
     out = HTMLOutputStream()
     out.write_text("foo 'bar'")
     assert str(out) == "foo &apos;bar&apos;"
Ejemplo n.º 14
0
 def test_can_write_text_with_quotes(self):
     out = HTMLOutputStream()
     out.write_text("foo \"bar\"")
     assert str(out) == "foo &quot;bar&quot;"
Ejemplo n.º 15
0
 def test_can_write_text_with_ampersand(self):
     out = HTMLOutputStream()
     out.write_text("foo & bar")
     assert str(out) == "foo &amp; bar"
Ejemplo n.º 16
0
 def test_can_write_text(self):
     out = HTMLOutputStream()
     out.write_text("foo")
     assert str(out) == "foo"