ElementTreeとdoctest


from elementtree.ElementTree import Element, tostring

def setTitle(t_title):
"""
>>> setTitle("Twisted Mind")
'<html><head><title>Twisted Mind</title></head></html>'

>>> setTitle("")
'<html><head><title /></head></html>'
"""


e_html = Element("html")
e_head = Element("head")
e_title = Element("title")
e_title.text = t_title

try:
e_head.append(e_title)
e_html.append(e_head)
except AssertionError, ae:
print ae

return tostring(e_html)

def _test():
import doctest
doctest.testmod()

if __name__ == "__main__":
_test()