Пример #1
0
    def test_procinc(self):
        doc = ['foo', [xmlist.PROCINC, 'a', ('b', 'c')]]
        xmlist.insert_ws(doc)
        self.assertEqual(doc, ['foo',
            '\n    ',
            [xmlist.PROCINC, 'a', ('b', 'c')],
            '\n'])
        xml = xmlist.serialize(doc)
        self.assertEqual('\n' + xml, '''
<foo>
    <?a b="c"?>
</foo>''')
Пример #2
0
    def test_fragment(self):
        doc = ['foo', 
                ['quux', 
            [xmlist.FRAGMENT, ['bar']]]]
        xmlist.insert_ws(doc)
        self.assertEqual(doc, ['foo',
            '\n    ',
            ['quux',
                '\n        ',
                [xmlist.FRAGMENT, ['bar']],
                '\n    '],
            '\n'])
        xml = xmlist.serialize(doc)
        self.assertEqual('\n' + xml, '''
<foo>
    <quux>
        <bar/>
    </quux>
</foo>''')
Пример #3
0
 def test_fragment(self):
     doc = xmlist.serialize(['spam', [xmlist.FRAGMENT, ['albatross']]])
     self.assertEqual(doc, '<spam><albatross/></spam>')
Пример #4
0
 def test_procinc(self):
     doc = xmlist.serialize(['spam', 
         [xmlist.PROCINC, 'albatross', ('spanish_inquisition', 'unexpected')]])
     self.assertEqual(doc, '<spam><?albatross spanish_inquisition="unexpected"?></spam>')
Пример #5
0
 def test_anything(self):
     with self.assertRaises(ValueError) as ex:
         xmlist.serialize(['foo', ['bar']])
     self.assertEqual(ex.exception.args[0], 'mode whatever not recognized')
Пример #6
0
 def test_html_nonempty_br(self):
     with self.assertRaises(ValueError) as ex:
         xmlist.serialize(['br', ['p']])
     self.assertEqual(ex.exception.args[0], 'br not empty')
Пример #7
0
 def test_html_br(self):
     doc = xmlist.serialize(['body', ['br']])
     self.assertEqual(doc, '<body><br></body>')
Пример #8
0
 def test_doctype(self):
     doc = xmlist.serialize([xmlist.DOCTYPE, 'HTML 5'])
     self.assertEqual(doc, '<!DOCTYPE html>\n')
Пример #9
0
 def test_text(self):
     doc = xmlist.serialize(['a', 'foo'])
     self.assertEqual(doc, '<a>foo</a>')
Пример #10
0
 def test_attr(self):
     doc = xmlist.serialize(['a', ('b', 'c')])
     self.assertEqual(doc, '<a b="c"/>')
Пример #11
0
 def test_sub_elem(self):
     doc = xmlist.serialize(['html', ['head'], ['body']])
     self.assertEqual(doc, '<html><head/><body/></html>')
Пример #12
0
 def test_unicode_attr_name(self):
     xml = xmlist.serialize(['spam', (u'\u20a0', 'spam & albatross')])
     self.assertEqual(xml, u'<spam \u20a0="spam &amp; albatross"/>')
Пример #13
0
 def test_unicode_element_name(self):
     xml = xmlist.serialize([u'spam\u20a0', 'test'])
     self.assertEqual(xml, u'<spam\u20a0>test</spam\u20a0>') 
Пример #14
0
 def test_unicode_text_node(self):
     xml = xmlist.serialize(['spam', u'\u20a0 99'])
     self.assertEqual(xml, u'<spam>\u20a0 99</spam>')
Пример #15
0
 def test_empty_elem(self):
     doc = xmlist.serialize(['foo'])
     self.assertEqual(doc, '<foo/>')
Пример #16
0
 def test_comment(self):
     doc = xmlist.serialize([xmlist.COMMENT, 'albatross'])
     self.assertEqual(doc, '<!--albatross-->')
Пример #17
0
 def test_cdata(self):
     doc = xmlist.serialize([xmlist.CDATA, '<albatross/>'])
     self.assertEqual(doc, '<![CDATA[<albatross/>]]>')
Пример #18
0
 def test_int_long(self):
     doc = xmlist.serialize(['doc', ['int', 42], ['long', long(42)]])
     self.assertEqual(doc, '<doc><int>42</int><long>42</long></doc>')
Пример #19
0
 def test_aah_wtf_are_you_doing(self):
     with self.assertRaises(ValueError) as ex:
         xmlist.serialize(['wtf', [13, 'albatross']])
     self.assertEqual(ex.exception.args[0], '[13, \'albatross\']')
Пример #20
0
 def test_unicode(self):
     doc = xmlist.serialize(['doc', u'foo'])
     self.assertEqual(doc, '<doc>foo</doc>')