当前位置: 首页>>代码示例>>Python>>正文


Python XMLBuilder.t1方法代码示例

本文整理汇总了Python中xmlbuilder.XMLBuilder.t1方法的典型用法代码示例。如果您正苦于以下问题:Python XMLBuilder.t1方法的具体用法?Python XMLBuilder.t1怎么用?Python XMLBuilder.t1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xmlbuilder.XMLBuilder的用法示例。


在下文中一共展示了XMLBuilder.t1方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestXMLBuilder

# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import t1 [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
#.........这里部分代码省略.........
开发者ID:alum,项目名称:pivotalburndown,代码行数:103,代码来源:test.py


注:本文中的xmlbuilder.XMLBuilder.t1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。