1
2
3 """
4 Tests that ElementMaker works properly.
5 """
6
7 from __future__ import absolute_import
8
9 import unittest
10
11 from lxml import etree
12 from lxml.builder import E
13
14 from .common_imports import HelperTestCase, _bytes
15
16
18 etree = etree
19
21 class StringSubclass(str): pass
22 wrapped = E.b(StringSubclass('Hello'))
23 self.assertEqual(_bytes('<b>Hello</b>'), etree.tostring(wrapped))
24
26 class UnknownType(object):
27 pass
28 self.assertRaises(TypeError, E.b, UnknownType())
29
33
35 self.assertRaises(ValueError, E.b, 'Hello', etree.CDATA('World'))
36
37
39 suite = unittest.TestSuite()
40 suite.addTests([unittest.makeSuite(BuilderTestCase)])
41 return suite
42
43 if __name__ == '__main__':
44 print('to test use test.py %s' % __file__)
45