本文整理汇总了Python中xmlbuilder.XMLBuilder.t方法的典型用法代码示例。如果您正苦于以下问题:Python XMLBuilder.t方法的具体用法?Python XMLBuilder.t怎么用?Python XMLBuilder.t使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlbuilder.XMLBuilder
的用法示例。
在下文中一共展示了XMLBuilder.t方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestXMLBuilder
# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import t [as 别名]
class TestXMLBuilder(object):
def setUp(self):
self.xml = XMLBuilder('root')
self.xml['xml_header'] = False
self.xml['formatted'] = False
def test_very_simple(self):
eq_(str(self.xml), "<root />")
def test_xml_header(self):
self.xml['xml_header'] = True
eq_(str(self.xml), '<?xml version="1.0" encoding="utf-8" ?>\n<root />')
def test_unicode(self):
self.xml.t
eq_(unicode(self.xml), u"<root><t /></root>")
def test_simple1(self):
self.xml.t
eq_(str(self.xml), "<root><t /></root>")
def test_simple2(self):
self.xml.t("some_data")
eq_(str(self.xml), "<root><t>some_data</t></root>")
def test_simple3(self):
self.xml.t(a='1')
eq_(str(self.xml), '<root><t a="1" /></root>')
def test_simple4(self):
self.xml.t("some data", a='1')
eq_(str(self.xml), '<root><t a="1">some data</t></root>')
def test_simple5(self):
self.xml << "some data"
eq_(str(self.xml), '<root>some data</root>')
def test_simple6(self):
self.xml << "some data" << '111' << '222'
eq_(str(self.xml), '<root>some data111222</root>')
@raises(ValueError)
def test_wrong_data1(self):
self.xml << 3
@raises(ValueError)
def test_wrong_data2(self):
self.xml.t(attr=3)
@raises(ValueError)
def test_wrong_data2(self):
self.xml.t("some_data", attr=3)
@raises(ValueError)
def test_wrong_data2(self):
self.xml.t(True, attr=3)
@raises(ValueError)
def test_wrong_data3(self):
self.xml.t(3)
test_formatter1_res = \
"""<root>
<t1 m="1">
<t2 />
</t1>
<t3>mmm</t3>
</root>"""
def test_formatter1(self):
self.xml['formatted'] = True
self.xml.t1(m='1').t2
self.xml.t3('mmm')
eq_(str(self.xml), self.test_formatter1_res)
test_formatter2_res = '<root>\n\t<t1 m="1">\n\t\t<t2 />\n\t</t1>\n\t<t3>mmm</t3>\n</root>'
def test_formatter2(self):
self.xml['formatted'] = True
self.xml['tabstep'] = '\t'
self.xml.t1(m='1').t2
self.xml.t3('mmm')
eq_(str(self.xml), self.test_formatter2_res)
def test_attrib(self):
self.xml.t1(m='1').t2
self.xml.t3('mmm')
eq_(str(self.xml), '<root><t1 m="1"><t2 /></t1><t3>mmm</t3></root>')
def test_with1(self):
with self.xml.tree_root:
pass
eq_(str(self.xml), "<root><tree_root /></root>")
def test_with2(self):
with self.xml.tree_root('rr'):
pass
#.........这里部分代码省略.........