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


Python XMLBuilder.tree_subroot方法代码示例

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


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

示例1: TestXMLBuilder

# 需要导入模块: from xmlbuilder import XMLBuilder [as 别名]
# 或者: from xmlbuilder.XMLBuilder import tree_subroot [as 别名]

#.........这里部分代码省略.........
        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

        eq_(str(self.xml), "<root><tree_root>rr</tree_root></root>")        

    def test_with3(self):
        with self.xml.tree_root(a='dt'):
            pass

        eq_(str(self.xml), '<root><tree_root a="dt" /></root>')        

    def test_with4(self):
        with self.xml.tree_root('mm', a='dt'):
            pass

        eq_(str(self.xml), '<root><tree_root a="dt">mm</tree_root></root>')        

    def test_with5(self):
        with self.xml.tree_root(a='dt'):
            self.xml << '11'

        eq_(str(self.xml), '<root><tree_root a="dt">11</tree_root></root>')        

    def test_with6(self):
        with self.xml.tree_root(a='dt'):
            self.xml << '11'
            self.xml.tt

        eq_(str(self.xml), '<root><tree_root a="dt">11<tt /></tree_root></root>')        

    def test_unicode(self):
        with self.xml.tree_root(a=u'dt'):
            self.xml << u'11'
            self.xml.tt('12')

        eq_(str(self.xml), u'<root><tree_root a="dt">11<tt>12</tt></tree_root></root>')        

    def test_unicode1(self):
        with self.xml.tree_root(a=u'dt'):
            self.xml << u'11'
            self.xml.tt('12')

        eq_(unicode(self.xml),
            u'<root><tree_root a="dt">11<tt>12</tt></tree_root></root>')        

    def test_unicode2(self):
        with self.xml.tree_root(a=u'dt'):
            self.xml << u'бла-бла-бла'
            self.xml.tt('12')

        eq_(str(self.xml).decode('utf8'),
            u'<root><tree_root a="dt">бла-бла-бла<tt>12</tt></tree_root></root>')        

    def test_with_all(self):
        self.xml.top
        with self.xml.tree_root('some data', attr='12'):
            self.xml.child1
            self.xml.child2('child data', attr='11')
            with self.xml.tree_subroot(attr='13'):
                self.xml.very_child('very data')
                with self.xml.tree_subsubroot:
                    pass

        eq_(str(self.xml), '<root>' + 
                             '<top />' + 
                                '<tree_root attr="12">some data' + 
                                    '<child1 />' + 
                                    '<child2 attr="11">child data</child2>' +
                                    '<tree_subroot attr="13">' +
                                        '<very_child>very data</very_child>'
                                        '<tree_subsubroot />' +
                                    '</tree_subroot>' +
                                '</tree_root>' + 
                            '</root>')
开发者ID:alum,项目名称:pivotalburndown,代码行数:104,代码来源:test.py


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