lxml.tests.test_builder
1
2 import unittest
3
4 """
5 Tests that ElementMaker works properly.
6 """
7
8 import sys, os.path
9 from lxml import etree
10 from lxml.builder import E
11
12 this_dir = os.path.dirname(__file__)
13 if this_dir not in sys.path:
14 sys.path.insert(0, this_dir)
15
16 from common_imports import HelperTestCase, BytesIO, _bytes
17
18
20 etree = etree
21
23 class StringSubclass(str): pass
24 wrapped = E.b(StringSubclass('Hello'))
25 self.assertEqual(_bytes('<b>Hello</b>'), etree.tostring(wrapped))
26
28 class UnknownType(object):
29 pass
30 self.assertRaises(TypeError, E.b, UnknownType())
31
35
37 self.assertRaises(ValueError, E.b, 'Hello', etree.CDATA('World'))
38
39
41 suite = unittest.TestSuite()
42 suite.addTests([unittest.makeSuite(BuilderTestCase)])
43 return suite
44
45 if __name__ == '__main__':
46 print('to test use test.py %s' % __file__)
47